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 Scalar #4

Closed
jvbianchi opened this issue Apr 2, 2018 · 6 comments
Closed

Custom Scalar #4

jvbianchi opened this issue Apr 2, 2018 · 6 comments

Comments

@jvbianchi
Copy link

How can I add some custom Scalar like Date, Time, JSON and Enum?

@jvbianchi
Copy link
Author

jvbianchi commented Apr 2, 2018

I tried to follow this tutorial, but I could not make it work with this framework.

@pleerock
Copy link
Contributor

pleerock commented Apr 2, 2018

There are two options in bootstrap you can use:

bootstrap({ 

     customResolvers: {
          /// ... your resolvers
     },
     customTypeDefs: `
          /// ... your type defs (scalars and others)
     `
});

@jvbianchi
Copy link
Author

jvbianchi commented Apr 2, 2018

I'm trying to use it like this:

import { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date';

bootstrap({ 
       customTypeDefs: [GraphQLDate, GraphQLTime, GraphQLDateTime],
});

but I got this error:

GraphQLError: Syntax Error GraphQL request (37:1) Unexpected Name "Date"

36:
37: Date,Time,DateTime
    ^

Am I using it wrong? Is there a example? I didn't find any in the documentation.

@pleerock
Copy link
Contributor

pleerock commented Apr 2, 2018

No, sorry I copy/pasted that block, actually customTypeDefs accepts a string, e.g. `customTypeDefs: "GraphQLDate \r\n GraphQLTime \r\n GraphQLDateTime"

@jvbianchi
Copy link
Author

Finally I could make it work, final code:

bootstrap({
  customResolvers: {
    Date: GraphQLDate,
    Time: GraphQLTime,
    DateTime: GraphQLDateTime,
  },
})

@gregwym
Copy link

gregwym commented Oct 16, 2018

Thanks to @jvbianchi , I got mine working. I also got https://github.com/taion/graphql-type-json work in the same way except I have to declare scalar JSON in graphql as well. Not sure why graphql-iso-date does not require that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants