Cannot execute Graphql query with custom input type api

  • Goal: Trying to use a custom input type for graphql resource.

  • Steps:

    1. Create a graphql resource whose input type is a custom object type (not a scalar type) in an app.
    2. Create a transformer (getRowsInput) to facilitate creating an input object
    3. Fill the input in the Variable section with the transformer (getRowsInput)
    4. Run the query - Get an error as below
[
   {
      "message":"Variable \"$input\" of non-null type \"GetASPartSalesListInput!\" must not be null.",
      "locations":[
         {
            "line":1,
            "column":23
         }
      ],
      "extensions":{
         "code":"BAD_USER_INPUT",
         "exception":{
            "stacktrace":[
               "GraphQLError: Variable \"$input\" of non-null type \"GetASPartSalesListInput!\" must not be null.",
               " at coerceVariableValues (/home/node/node_modules/graphql/execution/values.js:122:9)",
               " at getVariableValues (/home/node/node_modules/graphql/execution/values.js:45:21)",
               " at /home/node/node_modules/@apollo/gateway/dist/index.js:512:67",
               " at NoopContextManager.with (/home/node/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js:36:24)",
               " at ContextAPI.with (/home/node/node_modules/@opentelemetry/api/build/src/api/context.js:71:54)",
               " at NoopTracer.startActiveSpan (/home/node/node_modules/@opentelemetry/api/build/src/trace/NoopTracer.js:67:28)",
               " at ProxyTracer.startActiveSpan (/home/node/node_modules/@opentelemetry/api/build/src/trace/ProxyTracer.js:36:24)",
               " at ApolloGateway.validateIncomingRequest (/home/node/node_modules/@apollo/gateway/dist/index.js:506:39)",
               " at /home/node/node_modules/@apollo/gateway/dist/index.js:66:51",
               " at NoopContextManager.with (/home/node/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js:36:24)"
            ]
         }
      }
   }
]

  • Details:
    • The input is a custom type.
    • Other queries in other applications work well but still they show the error The value has to be of type 'string | number', you provided an object as attached in the Screenshots section
    • When I try to fetch another graph (another type) in the query, it throws an error.
      • ex)
query successfulQuery($input: SomeDataInput!) {
   successfulQuery(input: $input) {
      id
   }
}

query failedQuery($input: SomeDataInput!) {
   failedQuery(input: $input) {
      id
      relatedGraph { # <- this messes the whole query up
          name
      }
   }
}

  • Without the related graph, it works fine despite the error message with a union type..

  • It had worked okay so far, it started not working today without any changes made to the query.

  • Screenshots:

    • Graphql resource in Retool
      image

    • getRowsInput (object) transformer
      image

    • The error says The value has to be of type 'string | number', you provided an object.
      image

    • Failed error after executing the query

    • server.xyz/graphql (Specs)
      image

    • Successful result on /graphql

My guess

The main reason may be the graphql queries do not recognize the object type input (non-scalar) and does not accept the provided object as an input and blanks it.

Hi @Max!

This is a good guess, let's try "stringifying" the object before sending it.

Update the value for the input variable to:

{{JSON.stringify(getRowsInput.value)}}

Let us know how it goes! :slightly_smiling_face: