Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

RenameTypes + RenameObjectFields with interface resolveType not transforming correctly #43

Closed
m-sanders opened this issue Mar 19, 2020 · 4 comments

Comments

@m-sanders
Copy link

m-sanders commented Mar 19, 2020

Hello. We have been using this fork for a while now, and I would like to thank you for keeping Stitching going!

I posted an issue a while back #27 around schema transforms and I think I have ran into another issue with applying multiple transforms. We're using Prismic, a headless CMS with a GraphQL API, along with schema stitching. We're renaming types and object fields to make their API consistent with ours and to avoid naming conflicts. However I have ran into an issues where the transforms are not mapped correctly.

Here is a simplified version our transforms:

const schema = transformSchema(fakeRemoteSchema, [
  new RenameTypes(
    name => (name.startsWith("_") ? name : `P${pascalize(name)}`),
    {
      renameBuiltins: false,
      renameScalars: false
    }
  ),
  new RenameObjectFields((typeName, fieldName) => {
    if (typeName === "Query") return fieldName;

    // Remote uses leading underscores for special fields. Leave them alone.
    if (fieldName[0] === "_") return fieldName;

    // This issue appears to be with renaming `a_item`
    // if (fieldName === "a_item") return fieldName;

    return camelize(fieldName);
  })
]);

When querying on a renamed object field on a renamed interface implementation type e.g. aTransformedObjectField { ... on SomeInterface { field } }, we receive null rather than the data.

Please find a repo reproducing the issue here: https://github.com/m-sanders/graphql-tools-fork-43

@yaacovCR
Copy link
Owner

yaacovCR commented Mar 20, 2020

Will check this out hopefully next week, thank you for reproduction.

@yaacovCR
Copy link
Owner

I think the issue was just with nested object types, I don't think it had anything to do with interaction between RenameObjectFields and RenameTypes, or with the use of interfaces.

Should have been modifying AST via visit when leaving nodes rather than entering.

@yaacovCR
Copy link
Owner

Thanks for the reproduction, which made debugging this much easier. Let me know if this uncovers any additional bugs or I can be of any more help.

@m-sanders
Copy link
Author

Thanks again @yaacovCR I will look to complete the update later this week and get back to you if I encounter any other issues.

yaacovCR added a commit that referenced this issue Mar 23, 2020
yaacovCR added a commit that referenced this issue Mar 23, 2020
yaacovCR added a commit that referenced this issue Mar 26, 2020
yaacovCR added a commit that referenced this issue Mar 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants