-
-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override field types option for mergeSchemas #2051
Comments
Also, if the field changes the type from e.g. |
You can try new In your case, you can overwrite the existing |
Is it incorrect, because type
But how? :-/ I've tried Could you please provide an example of It looks like it's a good idea to add this example into |
onFieldTypeConflict: (existingField, otherField) => {
existingField.type = otherField.type;
} |
@ardatan I've tried the following: onFieldTypeConflict: (existingField, otherField) => {
Object.keys(existingField).forEach((key) => {
delete existingField[key];
});
Object.assign(existingField, otherField);
} to mutate I'm worried about the DX. What about making |
I've also found that |
@ardatan Just found https://www.apollographql.com/docs/apollo-server/api/graphql-tools/#ontypeconflict. The third Just curios, why |
Old You're right about DX so I changed the signature like you said. And now CI will release new canary version in a few minutes. Let me know if it works. |
|
Just tested |
Tests have been added for your cases; |
I was wrong. The
type Post {
id: ID!
title: String!
content: String!
published: Boolean!
}
type User {
id: ID!
}
type Post {
id: ID!
title: String
content: Int
fieldA: Int
fieldB: String
} The const schema = stitchSchemas({
schemas: [leftSchema, rightSchema],
}); outputs: type Post {
id: ID!
title: String
content: Int
fieldA: Int
fieldB: String
}
type User {
id: ID!
} The const schema = stitchSchemas({
schemas: [leftSchema, rightSchema],
onTypeConflict: (left, right) => right,
}); outputs: type Post {
id: ID!
title: String
content: Int
fieldA: Int
fieldB: String
}
type User {
id: ID!
} The const schema = stitchSchemas({
schemas: [leftSchema, rightSchema],
onTypeConflict: (left, right) => left,
}); outputs: type Post {
id: ID!
title: String!
content: String!
published: Boolean!
}
type User {
id: ID!
} I.e. BTW, is it a bug or by design? The The const schema = mergeSchemas({
schemas: [leftSchema, rightSchema],
onFieldTypeConflict: (left, right) => right,
}); outputs: type Post {
id: ID!
title: String
content: Int
published: Boolean!
fieldA: Int
fieldB: String
}
type User {
id: ID!
} The const schema = mergeSchemas({
schemas: [leftSchema, rightSchema],
onFieldTypeConflict: (left, right) => left,
}); outputs: type Post {
id: ID!
title: String!
content: String!
published: Boolean!
fieldA: Int
fieldB: String
}
type User {
id: ID!
} The only thing I've found, it doesn't merge arguments:
type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
): Boolean!
}
type Mutation {
doSomething(
argA: Int!
argB: Int
argC: Int!
argD: String
argF: Boolean
): Boolean!
} The const schema = mergeSchemas({
schemas: [leftSchema, rightSchema],
onFieldTypeConflict: (left, right) => right,
}); outputs: type Mutation {
doSomething(
argA: Int!
argB: Int
argC: Int!
argD: String
argF: Boolean
): Boolean!
} I've expected: type Mutation {
doSomething(
argA: Int!
argB: Int
argC: Int!
argD: String
argE: Int!
argF: Boolean
): Boolean!
} The const schema = mergeSchemas({
schemas: [leftSchema, rightSchema],
onFieldTypeConflict: (left, right) => left,
}); outputs: type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
): Boolean!
} I've expected: type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
argF: Boolean
): Boolean!
} |
I pushed a fix for arguments(I thought you need to override field completely) so you can try after CI releases the new canary version. |
Also, it seems I've found a bug in
type Test {
fieldA: Int
}
type Test {
fieldA: String
} The const schema = stitchSchemas({
schemas: [leftSchema, rightSchema],
onTypeConflict: (left, right) => right,
}); outputs: type Test {
fieldA: String
} The const schema = stitchSchemas({
schemas: [leftSchema, rightSchema],
onTypeConflict: (left, right) => left,
}); outputs: type Test {
fieldA: Int
} But for
type Query {
fieldA: Int
}
type Query {
fieldA: String
} the both outputs:
|
Ok but this is a different issue :) Schema stitching works in a different approach and aims a different thing. It might not be a good idea to overwrite |
Just tested merging arguments in
type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
): Boolean!
}
type Mutation {
doSomething(
argA: Int!
argB: Int
argC: Int!
argD: String
argF: Boolean
): Boolean!
} The const schema = mergeSchemas({
schemas: [leftSchema, rightSchema],
onFieldTypeConflict: (left, right) => right,
}); outputs: type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
argF: Boolean
): Boolean!
} I've expected: type Mutation {
doSomething(
argA: Int!
argB: Int
argC: Int!
argD: String
argE: Int!
argF: Boolean
): Boolean!
} The const schema = mergeSchemas({
schemas: [leftSchema, rightSchema],
onFieldTypeConflict: (left, right) => left,
}); outputs: type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
argF: Boolean
): Boolean!
} I've expected: type Mutation {
doSomething(
argA: Int!
argB: Int!
argC: Int
argD: Int!
argE: Int!
argF: Boolean
): Boolean!
} I.e. for |
@FluorescentHallucinogen Hi, I know this has been a long time, but have you found a solution to your issue here? I was curious to know what alternative solution you used. I have a similar need as you described here and I am trying to find a solution. |
@ardatan graphql-tools/packages/merge/CHANGELOG.md Line 30 in 761abba
mergeSchemas was not updated to support this. That was a rather large miss, since mergeSchemas provides no mechanism to resolve conflicts.
|
PRs are welcome! @shellscape |
@ardatan I'll see what I can do tonight. Please be aware that I have very limited time (as I'm sure you do as well) so please do try to help keep friction low. |
I'm working on a tool that shows a visual diff between two GraphQL schemas (e.g the previous and current versions of the same schema). Added fields are marked in green color, deleted in red and modified in yellow. It's built on top of graphql-voyager and uses @graphql-inspector/core under the hood.
In order to display the deleted fields in Voyager I merge both schemas using
mergeSchemas
from@graphql-tools/merge
.The problem is that if e.g.
Post.content
inschemaA
(the previous version of the schema) has theString!
(non-null) type, butPost.content
inschemaB
(the current version of the schema) has theString
(nullable) type, thePost.content
in the result ofmergeSchemas
of[schemaA, schemaB]
(in that order) will have theString!
type (from the previousschemaA
), not theString
type (from the currentschemaB
). See the image below.Could you please add an option for
mergeSchemas
that changes the behavior of merging non-null and nullable fields to use (override) the nullability from the latest schema from the array?The text was updated successfully, but these errors were encountered: