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

Additional resolver doesn't work after mutation #3180

Open
NicolasMahe opened this issue Nov 17, 2021 · 2 comments
Open

Additional resolver doesn't work after mutation #3180

NicolasMahe opened this issue Nov 17, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@NicolasMahe
Copy link
Contributor

NicolasMahe commented Nov 17, 2021

Describe the bug

I get the error Expected undefined to be an input type when an additional resolver is executed after a mutation.

The same resolver works perfectly in a query.

This resolver is define in yaml and stitch some data from another source to the type return by the query or the mutation.

To Reproduce
Steps to reproduce the behavior:

  • Setup with 2 sources. In my case it's a custom GraphQL API in Node and Postgraphile
  • Add a custom resolver to your .meshrc with an additional type def to a type you can query and create (for the mutation) on the custom GraphQL API server.
  • Make sure it's working by executing the query
  • Check the mutation, it should fail with Expected undefined to be an input type

Here is my partial .meshrc:

sources:
  - name: API
    handler:
      graphql:
        endpoint: ${API_URL}
  - name: Database
    handler:
      postgraphile:
        connectionString: ${DATABASE_URL}
additionalTypeDefs: |
  extend type Offer {
    makerAsset: Asset!
  }
additionalResolvers:
  - targetTypeName: Offer
    targetFieldName: makerAsset
    requiredSelectionSet: |
      {
        makerAssetId
      }
    sourceName: Database
    sourceTypeName: Query
    sourceFieldName: asset
    sourceArgs:
      id: '{root.makerAssetId}'

The query looks like (working):

query {
  offer(id: "a600728a-c4ce-4c9a-8530-ad323f8c87fe") {
    makerAsset {
      name
    }
  }
}

The not working mutation:

mutation createOffer($createOfferInput: OfferInput!) {
  createOffer(input: $createOfferInput) {
    id
    makerAssetId
    makerAsset {
      name
    }
  }
}

If I remove makerAsset, then it's working:

mutation createOffer($createOfferInput: OfferInput!) {
  createOffer(input: $createOfferInput) {
    id
    makerAssetId
  }
}

makerAssetId is returned with the right value

Environment:

  • OS: Mac Os
  • @graphql-mesh/cli: 0.43.6
  • @graphql-mesh/graphql: 0.20.3
  • @graphql-mesh/postgraphile: 0.16.1
  • NodeJS: v16

Additional context

I tried to replace the additional resolver with the typescript version but got the same problem.

Offer: {
    makerAsset: {
      selectionSet: `{
        makerAssetId
      }`,
      resolve: async (root, _args, context, info) => {
        try {
          const result = await context.Database.Query.asset({
            root,
            args: {
              id: root.makerAssetId,
            },
            context,
            info,
          })
          if (!result) throw new Error('result is false')
          return result
        } catch (error) {
          console.error(error)
          throw error
        }
      },
    },

The issue seems to come from the context.Database.Query.asset function.
If I replace the functions and return directly a dummy object (eg {name: "hello"} ) it's working.

@antho1404
Copy link

I have a similar issue running a custom resolver across 2 sources (1 query + 1 mutation).
This issue happens when I pass a variable to the initial request. This variable is passed to the subgraph creating a new operation that fails (certainly because the schema doesn't match the current type of the data anymore).

If it helps to debug/understand, by removing the operation created during the transformation here https://github.com/ardatan/graphql-tools/blob/a524d4da0ab768047c25bbaf8c9947ebabc035d0/packages/wrap/src/transforms/TransformInputObjectFields.ts#L87-L93, everything works as expected because it is not trying to transform the variable from the original request.

@ardatan
Copy link
Owner

ardatan commented Dec 28, 2021

@yaacovCR any ideas? Maybe we have a bug in stitching that prevents query calls from a mutation somehow?

@ardatan ardatan added the bug Something isn't working label Dec 28, 2021
@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
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants