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

Object given to custom scalar serialize changes type #454

Closed
moret opened this issue Oct 26, 2017 · 2 comments
Closed

Object given to custom scalar serialize changes type #454

moret opened this issue Oct 26, 2017 · 2 comments

Comments

@moret
Copy link

moret commented Oct 26, 2017

Hi! I've tried merging existing schemas which use graphql-custom-datetype as a custom scalar type. The merged schema however is turning the original resolved value at some point to a string - I could not figure out where - resulting in a serialization error on the custom scalar code. These are the steps to reproduce and what I expected to happen - although to be clear I'm not really familiar with custom scalar resolving, so I'm not sure if the resolved value should really be kept all the way until it's serialized or if it's expected to be changed at some point.

Steps to reproduce:
Run one of the following examples:

const {
  graphql,
  GraphQLObjectType,
  GraphQLSchema,
} = require('graphql');
const { mergeSchemas } = require('graphql-tools');
const CustomGraphQLDateType = require('graphql-custom-datetype');

const now = new Date();

const clockSchema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'clock',
    fields: {
      now: {
        resolve: () => now,
        type: CustomGraphQLDateType,
      }
    },
  })
});

graphql(
  clockSchema,
  '{ now }'
).then(result => {
  console.assert(
    result.data.now == now.toISOString(),
    'clock schema out of sync with the now'
  );
}).catch(e => {
  console.log(e);
});

const theGrandSchema = mergeSchemas({
  schemas: [clockSchema],
});

graphql(
  theGrandSchema,
  '{ now }'
).then(result => {
  console.log(result);
  console.assert(
    result.data.now == now.toISOString(),
    'the grand schema out of sync with the now'
  );
}).catch(e => {
  console.log(e);
});

Expected behaviour:
Queries on now to return an ISO timestamp - ex.: "2017-10-26T15:35:53.292Z".

Actual behaviour
Queries on now throw a TypeError: Field error: value is not an instance of Date from the custom scalar serialization because it gets a string instead of a Date.

@yaacovCR
Copy link
Collaborator

This should be fixed by #1307 see https://runkit.com/yaacovcr/custom-scalars

@yaacovCR
Copy link
Collaborator

Consolidating into #1306 .

@yaacovCR yaacovCR mentioned this issue Mar 29, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants