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

selectionSet is not passed to delegateToSchema/batchDelegateToSchema when using GraphQL Handlers #2720

Open
marcammann opened this issue Aug 29, 2021 · 0 comments

Comments

@marcammann
Copy link
Contributor

Describe the bug
When I was trying to use the (very convenient) way of accessing the API clients for GraphQL handlers, I found myself using selectionSet to be able re-map fields. I found it more convenient than using delegateToSchema or batchDelegateToSchema. However, the selectionSet when using an API SDK function is not being passed on to delegateToSchema / batchDelegateToSchema. Currently, a transform is created that transforms the request, but that only transforms the field if there is a selectionSet attached to a particular node in the original request. If the original request was for a scalar node, then there is no selectionSet associated and the request is not transformed.

To Reproduce
Steps to reproduce the behavior:

Using this in my resolver:

headline: {
      selectionSet: /* GraphQL */ `
        {
          id
        }
      `,
      resolve: async (root, args, context, info) => {
        const result = await context.Artifacts.Query.artifactsByIds({
          root,
          argsFromKeys: (keys: string[]) => {
            return { ids: keys }
          },
          key: root.id,
          context,
          info,
          selectionSet: /* GraphQL */ `
            {
              headline
            }
          `,
        })

        console.log('Headline Result: ', result)

        return result.headline
      },
    },

Expected behavior

In the above I'd expect that there is a GraphQL request being made with the selectionSet { headline }, but it is actually never attached and thus never returns any data for that headline.

I believe this is due to the fact that the request is only transformed if the original request (in the info object) also had a selectionSet. I think instead we should pass along the selectionSet into delegateToSchema / batchDelegateToSchema. I believe the relevant location is commonDelegateOptions on line 213 of get-mesh.ts.

Environment:

  • OS:
"@graphql-mesh/cli": "0.37.0",
    "@graphql-mesh/graphql": "0.18.9",
    "@graphql-mesh/transform-encapsulate": "0.1.57",
    "@graphql-mesh/transform-naming-convention": "0.6.59",
    "@graphql-mesh/transform-prefix": "0.6.58",
    "@graphql-mesh/transform-rename": "0.9.8",
    "@graphql-tools/batch-delegate": "8.0.12",
    "@graphql-tools/delegate": "8.1.1",
  • NodeJS:
@theguild-bot theguild-bot mentioned this issue Aug 11, 2022
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant