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

Subresolver paremeters depends on mocks settings #4398

Closed
deftomat opened this issue Jul 20, 2020 · 3 comments
Closed

Subresolver paremeters depends on mocks settings #4398

deftomat opened this issue Jul 20, 2020 · 3 comments

Comments

@deftomat
Copy link
Contributor

deftomat commented Jul 20, 2020

To have a strongly typed code, we are using a sort of "inline" subresolvers which allows us to defer resolution as necessary.

Example:

const typeDefs = gql`
  type Query {
    user: User!
  }

  type User {
    id: String!
    tags(filter: String!): [String!]!
  }
`;

const resolvers = {
  Query: {
    user: () => {
      return {
        id: "abc123",
        tags: (first, second) => {
          return ["admin", "internal"].filter(v => v.includes(first.filter));
        }
      };
    }
  }
};

These subresolvers are little bit different as the first arg is not the parent but variables.

It all works when mocks are disabled. Enabling the mocks will add the parent arg and basically moves the variables into the second arg.

Please see https://codesandbox.io/s/adoring-torvalds-nfdff?file=/index.js

When mocks are disabled, user's tags are filterable by variable, however, enabling mocks will broke it as filter value will be in the second argument.

Looks like it is caused by ardatan/graphql-tools#1807

@deftomat
Copy link
Contributor Author

deftomat commented Oct 7, 2020

graphql-tools@7 fixed this issue. So, upgrade to the latest version is necessary.

@yaacovCR
Copy link

yaacovCR commented Oct 7, 2020

Soon to be released, available now as alpha:

ardatan/graphql-tools#1935 (comment)

@glasser
Copy link
Member

glasser commented Oct 21, 2022

The mocks feature of Apollo Server was just a simple invocation of a function from a particular old version of graphql-tools, and so in Apollo Server 4 we've removed that integration in favor of letting you use graphql-tools yourself directly (which also means you can upgrade yourself when bugs in it are fixed).

@glasser glasser closed this as completed Oct 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
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

3 participants