Skip to content
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

Extending schema with input which got suppressed by disableDefaultMutations does not work #523

Closed
pahlke opened this issue Sep 17, 2019 · 3 comments

Comments

@pahlke
Copy link

pahlke commented Sep 17, 2019

Hello,
I am using "disableDefaultMutations: true" in order to write the mutations by myself. When I then extend the schema with an input type with the same name as one which would have been generated automatically, I get at an error message that this type is already defined, although it is definitely not in the final schema. Is this intended? Or how can this be circumvented?

@pahlke pahlke changed the title Extending schema with types which got suppressed by disableDefaultMutations does not work Extending schema with input which got suppressed by disableDefaultMutations does not work Sep 17, 2019
@benjie
Copy link
Member

benjie commented Sep 17, 2019

The reason you're getting this is because we're creating the types ahead of time even though they're not used. This has turned out to be a bad practice, and we've tried to move away from it in many places but cannot do so for this in the V4 chain without it being a breaking change (I think).

Here's where the types are defined:

TablePatchType = newWithHooks(
GraphQLInputObjectType,
{
description: `Represents an update to a \`${tableTypeName}\`. Fields that are set will be updated.`,
name: inflection.patchType(TableType),
},
{
__origin: `Adding table patch type for ${describePgEntity(
table
)}. You can rename the table's GraphQL type via:\n\n ${sqlCommentByAddingTags(
table,
{
name: "newNameHere",
}
)}`,
pgIntrospection: table,
isPgRowType: table.isSelectable,
isPgCompoundType: !table.isSelectable,
isPgPatch: true,
pgAddSubfield(
fieldName,
attrName,
pgType,
spec,
typeModifier
) {
pgPatchInputFields[fieldName] = {
name: attrName,
type: pgType,
typeModifier,
};
return spec;
},
},
true // Safe to skip this if no fields support updating
);
TableBaseInputType = newWithHooks(
GraphQLInputObjectType,
{
description: `An input representation of \`${tableTypeName}\` with nullable fields.`,
name: inflection.baseInputType(TableType),
},
{
__origin: `Adding table base input type for ${describePgEntity(
table
)}. You can rename the table's GraphQL type via:\n\n ${sqlCommentByAddingTags(
table,
{
name: "newNameHere",
}
)}`,
pgIntrospection: table,
isPgRowType: table.isSelectable,
isPgCompoundType: !table.isSelectable,
isPgBaseInput: true,
pgAddSubfield(
fieldName,
attrName,
pgType,
spec,
typeModifier
) {
pgBaseInputFields[fieldName] = {
name: attrName,
type: pgType,
typeModifier,
};
return spec;
},
}
);
}

Note these types are not only used for the default CRUD mutations, but also as inputs for the various PostgreSQL functions you can create, so we cannot simply disable them if disableDefaultMutations is set 😞

However, all is not lost. If you're certain that you don't need any of these types you can supply alternative inflectors for them using makeAddInflectorsPlugin so that the originals are named differently, freeing up their original names for you to use.

@ab-pm
Copy link
Contributor

ab-pm commented Sep 18, 2019

A different, if not better, workaround than renaming the input types would be to @omit create,update the fields that you don't want in the input type, and use extend input … { … } in the schema extension to customise the rest. Maybe you don't have to customise it at all, you can just refer to the type in your extendSchemaPlugin and it will end up in the final schema because you referenced it.

@benjie
Copy link
Member

benjie commented Sep 23, 2019

I'm closing this issue because it is not a bug, these type names should be reserved for function and mutation inputs.

@benjie benjie closed this as completed Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants