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

Unable to add date scalar type #197

Closed
dcworldwide opened this issue Nov 12, 2016 · 4 comments
Closed

Unable to add date scalar type #197

dcworldwide opened this issue Nov 12, 2016 · 4 comments

Comments

@dcworldwide
Copy link

dcworldwide commented Nov 12, 2016

I'm trying to add a Date scalar type as per the docs. But schema compilation throws an error.

http://dev.apollodata.com/tools/graphql-tools/scalars.html

Code


const rootSchema = [`

scalar Date

type User {
    id: String
    created: Date
}

type Query {
 removed to keep things terse 
}

schema {
  query: Query
}

`];

const rootResolvers = {
    Date: new GraphQLScalarType({
        name: 'Date',
        description: 'Date custom scalar type',
        parseValue(value) {
            return new Date(value); // value from the client
        },
        serialize(value) {
            return value.getTime(); // value sent to the client
        },
        parseLiteral(ast: any) {
            if (ast.kind === Kind.INT) {
                return parseInt(ast.value, 10); // ast value is always in string format
            }
            return null;
        },
    }),
    Query: {
    },
};

// Compose schemas / resolvers
    const schema = [...rootSchema];
const resolvers = Object.assign({}, rootResolvers);

// Create schema
const executableSchema = makeExecutableSchema({
    typeDefs: schema,
    resolvers,
});

export default executableSchema;

Error

/Users/Danijel/projects/am/am-api/node_modules/graphql-tools/dist/schemaGenerator.js:224
[1]                 throw new SchemaError(typeName + " was defined in resolvers, but it's not an object");
[1]                 ^
[1] Error: Date was defined in resolvers, but it's not an object
[1]     at /Users/Danijel/projects/am/am-api/node_modules/graphql-tools/dist/schemaGenerator.js:224:23
[1]     at Array.forEach (native)
[1]     at /Users/Danijel/projects/am/am-api/node_modules/graphql-tools/dist/schemaGenerator.js:215:49
[1]     at Array.forEach (native)
[1]     at addResolveFunctionsToSchema (/Users/Danijel/projects/am/am-api/node_modules/graphql-tools/dist/schemaGenerator.js:210:35)
[1]     at _generateSchema (/Users/Danijel/projects/am/am-api/node_modules/graphql-tools/dist/schemaGenerator.js:44:5)
[1]     at Object.makeExecutableSchema (/Users/Danijel/projects/am/am-api/node_modules/graphql-tools/dist/schemaGenerator.js:56:20)
[1]     at Object.<anonymous> (/Users/Danijel/projects/am/am-api/lib/graphQL/schema.js:208:42)
[1]     at Module._compile (module.js:556:32)
[1]     at Object.Module._extensions..js (module.js:565:10)
[1]     at Module.load (module.js:473:32)
[1]     at tryModuleLoad (module.js:432:12)
[1]     at Function.Module._load (module.js:424:3)
[1]     at Module.require (module.js:483:17)
[1]     at require (internal/module.js:20:19)
[1]     at Object.<anonymous> (/Users/Danijel/projects/am/am-api/lib/router.js:5:18)
@ghost
Copy link

ghost commented Nov 14, 2016

Hi, for your information there have been recent modifications on the custom scalars. See #189

Just a question : which version of the graphql-tools npm package do you have in node_modules/ ?

@thebigredgeek
Copy link
Contributor

@oricordeau it looks like this is broken for 0.8.1. It almost looks like the docs were rolled out without the code to support it!!

@ghost ghost mentioned this issue Nov 17, 2016
4 tasks
@stubailo
Copy link
Contributor

Should be fixed in 0.8.2! Thanks for reporting and sorry for the delay.

@somil-nagarro
Copy link

somil-nagarro commented Dec 8, 2017

same issue for custom enums. Any solutions provided?

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

4 participants