-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
Merge conflictive types #642
Comments
I can confirm that merging types are working only on Root and Query & Mutation level. this type type Article {
id: ID!
name: String
} and this type type Article {
created_at: String
} would resolve in this type: type Article {
id: ID!
name: String
created_at: String
} |
Hey, function mergeObjectTypes(leftType, rightType) {
if (!rightType) {
return leftType;
}
if (leftType.constructor.name !== rightType.constructor.name) {
throw new TypeError(`Cannot merge with different base type. This : ${leftType.constructor.name}, other: ${rightType.constructor.name}`);
}
if (!leftType.getFields) {
return leftType;
}
// Create new object
const mergedType = Object.create(leftType);
// Add name and description of leftType and fallback to rightType
if (!mergedType.name) mergedType.name = rightType.name;
if (!mergedType.description) mergedType.description = rightType.description;
// Populate an array with existing types to compare against
const mergedFields = new Set();
mergedType.astNode.fields.map((field) => {
mergedFields.add(field.name.value);
});
rightType.astNode.fields.map((field) => {
if (!mergedFields.has(field.name.value)) {
mergedType.astNode.fields.push(field);
}
});
return mergedType;
} But my implementation actually has no effect towards the final merged schema. The mergedType I'm returning does have the added fields in the |
Is there any example of how you can actually merge schemas (left and right type) that works? |
I have yet to find one. That's the reason I tried to build it myself. |
It seems that merge only works for top level Query. |
Yes, the implementation of |
In my opinion, this is an important issue, since I want to use merging to combine my GraphQL microservice architecture. I think a lot of other users trying to implement similar architectures might benefit from this fix/enhancement as well. The gramps-project from IBM, for example, is built entirely around |
I want to merge two schemas, from remote servers, with conflictive types.
Schema Server 1:
Schema Server 2:
I try to solve this, using this approach:
But this mergeObjectTypes function only resolves the last apollo-link server.
How can i fix this?
Github complete example: https://github.com/francescjaume/graphql-microservices-example
The text was updated successfully, but these errors were encountered: