graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Adding a computed property with a non-primitive/non-scalar return type breaks the schema when stitching

Open sondremare opened this issue 2 years ago • 5 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [x] 2. A failing test has been provided
  • [x] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

Attempting to add a computed property with a non-scalar return type breaks the schema when stitching.

One subschema defines the following type:

type User {
    id: ID!
    name: String!
}

And the other subschema defines the extension of the User-type:

type ComplexType {
    someProperty: Boolean
}
    
type User {
    id: ID!
    isSomeComplexType: ComplexType @computed(selectionSet: "{ name }")
}

When introspecting the schema, or running assertValidSchema from the graphql-package, an error is thrown: Error: Type ComplexType must define one or more fields.

To Reproduce

Repository has instructions in readme on how to reproduce. https://github.com/sondremare/graphql-tools-stitch-reproduction

Expected behaviour

I expect a list of users where the field isSomeComplexType is resolvable

Environment:

  • OS: macOS Monterey (12.5.1)
  • @graphql-tools/stitch": "^8.7.34,
  • @graphql-tools/stitching-directives": "^2.3.24,
  • NodeJS: 16.13.2

Additional context

sondremare avatar Jan 10 '23 07:01 sondremare

I have made a local solution for the problem in the draft https://github.com/ardatan/graphql-tools/pull/4957. However I made another test fail, and I am a bit unsure of my attack angle for this problem: Care to take a look @ardatan ?

sondremare avatar Jan 10 '23 15:01 sondremare

Any points/hints to where I can look in the code to figure out a solution @ardatan ?

sondremare avatar Jan 25 '23 07:01 sondremare

We've encountered the same challenge. This would help us as well

Hessels90 avatar Mar 09 '23 12:03 Hessels90

You have to send name as key as well. See https://the-guild.dev/graphql/stitching/handbook/foundation/computed-fields#summary Otherwise the other service is not able to receive it from the gateway.

ardatan avatar Mar 09 '23 12:03 ardatan

I do not understand what you mean by having to "send name as key as well", care to elaborate?

sondremare avatar Mar 21 '23 10:03 sondremare

Sorry for the late response!| It seems your reproduction seems to be working as expected with the latest versions! https://github.com/ardatan/graphql-tools/pull/6121 Let us know if you have any further issues!

ardatan avatar May 01 '24 14:05 ardatan