-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add a new graphql.typeName
for the structure
field to support deduplication of GraphQL types
#8480
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 15c0e11:
|
Can you add an example to the test sandbox? |
graphql.typeName
for the structure
field to support deduplication of GraphQL types
8dffd03
to
f00e496
Compare
4e857af
to
15c0e11
Compare
This relates to a more general problem I've hit around GraphQL type re-usage across fields and custom mutations. Currently there's no way (that I know of; please correct me) that let's you share/reuse a GraphQL types between multiple virtual fields, nor is it possible to share a GraphQL type between a virtual fields and GraphQL extensions. Part if the problem is that, when you need to refer to existing list types for a virtual field, you use the In my current project we have managed to reuse types across multiple GraphQL extensions by closuring over export const extendGraphqlSchema: ExtendGraphqlSchema = graphql.extend((base) => {
const loaders = buildLoaders(base);
const dynamicGqlTypes = buildDynamicGqlTypes(base, loaders);
return {
query: {
dodads: dodadsQuery({ dynamicGqlTypes }),
thingamajigs: thingamajigsQuery({ dynamicGqlTypes }),
search: searchQuery({ base, dynamicGqlTypes }),
},
mutation: {
createDodad: createDodadMutation({ dynamicGqlTypes }),
updateDodad: updateDodadMutation({ dynamicGqlTypes }),
createThingamajig: createThingamajigMutation({ dynamicGqlTypes }),
updateThingamajig: updateThingamajigMutation({ dynamicGqlTypes }),
},
};
}); If you could lazily create and cache them like this... let dodadGraphQLType;
function getDodadGraphQLType(base) {
if (dodadGraphQLType) return dodadGraphQLType;
dodadGraphQLType = graphql.object({
name: 'DodadOutput',
fields: {
// ...
},
});
return dodadGraphQLType;
} Then you could just pull the types you needed into each mutation separately but this doesn't work because Keystone creates two schemas (the standard one and another for Note, even if this did work, you'd still have problems re-using the types between extensions and virtual fields because (as above) when defining virtual field types you have a Shouldn't Keystone have a single place we can define GraphQL types for a schema? Then developers can refer to those types by their GraphQL type names (which is always unique) when they're needed for custom queries/mutations, virtual fields, structure fields, etc. This new config ( |
Adds
graphql.typeName
to structured JSON field to allow structured JSON to have global typesNote if the types don't match it will cause GraphQL runtime errors, this will also not work with relationships