Hi,
I tried to use a custom scalar type Date in my schema, written with the GraphQL schema language.
It seems that buildSchema takes only one param.
Is there a way to "register" my custom type in order to let buildSchema know what is the Date type?
import { buildSchema } from 'graphql';
import { GraphQLScalarType } from 'graphql/type';
const Date = new GraphQLScalarType({
name: 'Date',
serialize(value) {
return value;
},
});
const schema = buildSchema(`
scalar Date
type User {
id: Int
firstName: String
lastName: String
sex: String
birthDate: Date
}
type Query {
users(id: Int): [User]
}
`);
const root = {
users: async ({ id }) => {
const users = db('users');
return await id ? users.where('id', id) : users;
},
}
The value of birthDate is 1986-02-11 07:13:14. I expect the same after the serialization.
My query in graphiQL:
{
users(id: 1) {
id
firstName
lastName
sex
birthDate
}
}
The result:
{
"data": {
"users": [
{
"id": 1,
"firstName": "Midas",
"lastName": "Bokma",
"sex": "m",
"birthDate": null
}
]
},
"errors": [
{
"message": "Expected a value of type \"Date\" but received: Tue Feb 11 1986 07:13:14 GMT-0600 (CST)",
"locations": [
{
"line": 7,
"column": 5
}
]
}
]
}
Hi,
I tried to use a custom scalar type
Datein my schema, written with the GraphQL schema language.It seems that
buildSchematakes only one param.Is there a way to "register" my custom type in order to let
buildSchemaknow what is theDatetype?The value of
birthDateis1986-02-11 07:13:14. I expect the same after the serialization.My query in graphiQL:
The result:
{ "data": { "users": [ { "id": 1, "firstName": "Midas", "lastName": "Bokma", "sex": "m", "birthDate": null } ] }, "errors": [ { "message": "Expected a value of type \"Date\" but received: Tue Feb 11 1986 07:13:14 GMT-0600 (CST)", "locations": [ { "line": 7, "column": 5 } ] } ] }