Skip to content

serialize and parseValue are not called for input parameter of a customised scalar type #2282

Closed
@zhaoyi0113

Description

@zhaoyi0113

I define a schema like this:

const query = new GraphQLObjectType({
    name: 'Query',
    fields: {
      quote: {
        type: queryType,
        args: {
          id: { type: QueryID }
        },
      },
    },
  });
const schema = new GraphQLSchema({
    query,
  });

The QueryID is a customised scalar type.

const QueryID = new GraphQLScalarType({
  name: 'QueryID',
  description: 'query id field',
  serialize(dt) {
    // value sent to the client
    return dt;
  },
  parseLiteral(ast) {
    if (ast.kind === 'IntValue') {
      return Number(ast.value);
    }
    return null;
  },
  parseValue(v) {
    // value from the client
    return v;
  },
});

I found that the serialize and parseValue methods are not called when clients send query to my server. I can see parseLiteral is called correctly.
In most of the document I can find, they use gql to define schema but in my case I am using GraphQLSchema object. Is this the root cause?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions