Search code examples
mysqlnode.jsgraphqlisodate

GraphQL : must be Output Type but got: undefined Error


I was trying to fetch a MySQL Date from database and output it with graphql. My application builds and runs without any issue. But in graphql ui, it says below error.

{
  "errors": [
    {
      "message": "The type of Tour.arrival_date must be Output Type but got: undefined."
    }
  ]
}

My type.js file looks like this.

let {
    GraphQLID,
    GraphQLString,
    GraphQLInt,
    GraphQLFloat,
    GraphQLObjectType,
    GraphQLNonNull,
    GraphQLDate,
    GraphQLList
} = require('graphql')




// Defines the type
module.exports = new GraphQLObjectType({
    name: 'Tour',
    description: 'A Tour',
    fields: {
        id: {
            type: new GraphQLNonNull(GraphQLID)
        },
        name: {
            type: new GraphQLNonNull(GraphQLString)
        },
        pax_count: {
            type: GraphQLInt
        },
        arrival_date: {
            type: GraphQLDate
        }

    }
})

I am using below library for ISO Date.

https://www.npmjs.com/package/graphql-iso-date

Can someone please advice me what could be the possible issue on this? Please note that I'm really new to GraphQL.

Thanks Buddhika


Solution

  • You are importing GraphQLDate from graphql, but graphql does not export a variable with that name because there is no built-in scalar for Date in GraphQL.js. If you're using graphql-iso-date, then import the appropriate scalar as described in the documentation:

    const { GraphQLDate } = require('graphql-iso-date')