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
transformSchema simplifies schema returned from makeExecutableSchema #1006
Comments
This looks to me like a naming issue, which your second answer resolved by creating new variable names for all the schemas you're working with here. You're linter should have caught that you're trying to reassign a |
@slaymance Oh sorry about that. I didn't test that example. Here is a working example which anyone can run to reproduce the bug: https://github.com/taylorgoolsby/graphql-directive-private/tree/graphql-tools-transform-bug I will also edit my original post to correct it. |
@taylorgoolsby Ah thanks for putting together that repo, it's super helpful for understanding this behavior! When calling This brings up some interesting discussion points regarding schema transforms. Should the GraphQL spec include the possibility of custom properties for GraphQL types? If not, should the Apollo By the way, the cause of this behavior is a function in const recreatedGraphQLObject = new graphql_1.GraphQLObjectType({
name: type.name,
description: type.description,
astNode: type.astNode,
isTypeOf: keepResolvers ? type.isTypeOf : undefined,
fields: function () {
return fieldMapToFieldConfigMap(fields_1, resolveType, keepResolvers);
},
interfaces: function () { return interfaces_1.map(function (iface) { return resolveType(iface); }); },
});
return { ...type, ...recreatedGraphQLObject }; That should cause the tests in your bug demonstration repo to pass. |
@slaymance Thanks for the explanation. Now, I understand why the custom properties are lost, but I also agree that I was expecting the parameter into the Transform functions to be equal to the schema passed into I don't think it's a big deal, since even though custom properties are lost, the directives are not, so you can still reference |
Hi and apologies for hijacking the topic - but I think I stumbled upon some behaviour related to what @taylorgoolsby has noted. If it's not, let me know and I'll open a new issue. I have a simple schema defining an enum PersonType {
ADULT
CHILDREN
INFANT
} {
PersonType: {
ADULT: 'ADT',
CHILDREN: 'CHD',
INFANT: 'INF'
}
} This works fine in queries/mutations if I use the schema returned by {
"timeThrown": "2019-01-09T20:00:11.786Z",
"name": "GraphQLError",
"message": "Expected a value of type \"PersonType\" but received: \"ADULT\""
} If you don't ask for this particular field in your response, everything works just fine. I'm using /* schema.js */
const schema = makeExecutableSchema({ ... });
// Works as expected
// module.exports = schema;
// Breaks enums (empty transformations array)
module.exports = transformSchema(schema, []); This happens for every other
Any pointers? |
@nfantone I think this line is the beginning of why the input and out schemas are different: https://github.com/apollographql/graphql-tools/blob/master/src/transforms/transformSchema.ts#L15 And above @slaymance describes |
@taylorgoolsby Right. So are we in agreement that this is, indeed, a bug? I'm not sure what to make of this as I never got around this situation. |
I'm not sure if it's a bug or a feature. I'm not part of the apollo team. But as an end user of |
Thanks 👍. An official take would be nice here. Words seem slow around these parts, unfortunately. |
Closing. See solution above in #1006 (comment) Additional comments are tracked in #1056 |
Here is an example which you can use to replicate the problem:
https://github.com/taylorgoolsby/graphql-directive-private/tree/graphql-tools-transform-bug
The README on that branch explains the bug in detail.
And this file has code to reproduce the bug:
https://github.com/taylorgoolsby/graphql-directive-private/blob/graphql-tools-transform-bug/__tests__/main-test.ts
I need this because I want my
SchemaDirectiveVisitor
to visit object, fields, and whatnot, and I want to mark each object or field with some special markings.Then I want to use
transformSchema
to discover these markings and transform the schema accordingly.This is my workaround right now:
The text was updated successfully, but these errors were encountered: