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.
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.
@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 馃檪
Looks like it's fixed in v2.20.0 https://github.com/apollographql/graphql-tools/compare/v2.19.0...v2.20.0
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.
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.
I am still running into this issue. Is there any known work around?
Should be fixed in graphql-tools-fork.
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! :)
Most helpful comment
@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 馃檪