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 ignored when overrides existing fields #6637

Open
4 tasks
sixmen opened this issue Oct 31, 2024 · 0 comments
Open
4 tasks

selectionSet is ignored when overrides existing fields #6637

sixmen opened this issue Oct 31, 2024 · 0 comments

Comments

@sixmen
Copy link
Contributor

sixmen commented Oct 31, 2024

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 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.

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

Describe the bug

When I use stitch & delegate, some fields described in selectionSet does not pass to the source schema.

To Reproduce Steps to reproduce the behavior:

https://codesandbox.io/p/devbox/t2xglt

import { buildSchema, graphql } from 'graphql';
import { addResolversToSchema } from '@graphql-tools/schema';
import { stitchSchemas } from '@graphql-tools/stitch';
import { delegateToSchema } from '@graphql-tools/delegate';

const sub_schema = addResolversToSchema({
  schema: buildSchema(`
  type Query {
    current_user: User
  }

  type User {
    id: ID!
    name: String!
    age: Int!
  }
`),
  resolvers: {
    Query: {
      current_user: () => ({ id: '5', name: 'John Doe', age: 10 }),
    },
  },
});

const stitched_schema = stitchSchemas({
  subschemas: [
    {
      schema: sub_schema,
      createProxyingResolver: (options) => {
        return (_parent, _args, context, info) => {
          const operationName = info.operation.name ? info.operation.name.value : undefined;
          return delegateToSchema({
            schema: options.subschemaConfig,
            operation: options.operation,
            context,
            info,
            operationName,
          });
        };
      },
    },
  ],
  resolvers: {
    User: {
      name: {
        selectionSet: '{ age }',
        resolve: (parent) => `${parent.name}(${parent.age})`,
      },
    },
  },
});

console.log((await graphql({ schema: stitched_schema, source: '{ current_user { name } }' })).data.current_user.name);

Expected behavior

  • expected: John Doe(10)
  • real result: John Doe(undefined)

Environment:

  • OS: macOS 13.6.7
  • @graphql-tools/delegate: 10.0.10
  • NodeJS: 20.18.0

Additional context

It works well with @graphql-tools/delegate: 10.0.9

I think #6134 makes this problem.
If I change if (!skipAddingDependencyNodes) to if (true) (ignore changes of the PR), I can get the correct answer.

If I add an another field instead of overriding existing fields (ie. name -> name_age), it works well.

ardatan added a commit to graphql-hive/gateway that referenced this issue Nov 15, 2024
enisdenjo pushed a commit to graphql-hive/gateway that referenced this issue Nov 15, 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