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

Custom scalars break when being stitched together by mergeSchemas #501

Closed
fusepilot opened this issue Nov 22, 2017 · 8 comments
Closed

Custom scalars break when being stitched together by mergeSchemas #501

fusepilot opened this issue Nov 22, 2017 · 8 comments

Comments

@fusepilot
Copy link

Possibly related #454, #486

Tried with the custom Date scalar example from https://www.apollographql.com/docs/graphql-tools/scalars.html#Date-as-a-scalar. It works when the whole schema is created using a single makeExecutableSchema. But when using mergeSchemas it throws value.getTime is not a function.

Launchpad without mergeSchemas that works: https://launchpad.graphql.com/mkwqx4l99
Launchpad with mergeSchemas that doesn't work: https://launchpad.graphql.com/93ql188wr

Not sure if this is expected behavior or a bug.

@freiksenet
Copy link
Contributor

Thanks for reporting!

For future reference:

So the way it works is that in direct schema merging, we, naturally, want to preserve the scalars coming from subschemas (cause we can and they might be used internally). However, when you execute a subschema, you get the serialized result in your resolver, which is then broken because GraphQL expects a un-serialized result there.

I'll update our tests to reflect that this is broken and think more on how to fix it.

@kylesome
Copy link

@freiksenet Just wondering if there is an update on this one? Or is there a work around to use custom scalars with mergeSchemas ? Much appreciated 🙂

@ihealthdavid
Copy link

Looks like it's fixed in v2.20.0 v2.19.0...v2.20.0

@ndarilek
Copy link

Are we sure it's fixed? Here's my DateTime custom scalar:

import {GraphQLScalarType} from "graphql"
import {Kind} from "graphql/language"

const schema = "scalar DateTime"

const resolver = {
  DateTime: new GraphQLScalarType({
    name: "DateTime",
    description: "DateTime type",
    parseValue: (value) => new Date(value),
    serialize: (value) => {
      if(typeof(value) == "number")
        return value
      else
        return value.getTime()
    },
    parseLiteral(ast) {
      if(ast.kind == Kind.INT)
        return parseInt(ast.value, 10)
      return null
    }
  })
}

export default {schema, resolver}

And my mergeSchema call:

const schema = mergeSchemas({
  schemas: [DateTime.schema, auth.schema, orders.schema],
  resolvers: [DateTime.resolver, auth.resolvers, orders.resolvers]
})

But I still get:

Error: No such type: DateTime

Is there some other way I'm supposed to specify custom scalars?

Thanks. Using 2.23.1.

@ndarilek
Copy link

OK, not entirely fixed. If my schema is only:

const schema = `
scalar DateTime
`

then the scalar doesn't appear to be created, and I'm told it exists in the resolvers field but not in the types.

If I have:

const schema = `

scalar DateTime

enum Role {
...

then everything works fine.

@de55
Copy link

de55 commented Aug 27, 2019

I am still running into this issue. Is there any known work around?

@yaacovCR
Copy link
Collaborator

Should be fixed in graphql-tools-fork.

https://www.npmjs.com/package/graphql-tools-fork

@kamilkisiela
Copy link
Collaborator

We recently released an alpha version of GraphQL Tools (#1308) that should fix the issue.

Please update graphql-tools to next or run:

npx match-version graphql-tools next

Let us know if it solves the problem, we're counting for your feedback! :)

@yaacovCR yaacovCR mentioned this issue Mar 27, 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

9 participants