Skip to content

Instantly share code, notes, and snippets.

@a7v8x
Created May 2, 2020 11:24
Show Gist options
  • Save a7v8x/00805e7957617eb9904eefc32a48ae1d to your computer and use it in GitHub Desktop.
Save a7v8x/00805e7957617eb9904eefc32a48ae1d to your computer and use it in GitHub Desktop.
How to define GraphQL custom scalars - https://atheros.ai/blog/how-to-design-graphql-custom-scalars
import {
GraphQLString,
GraphQLID,
GraphQLObjectType,
GraphQLNonNull,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean,
} from 'graphql';
import DateTime from '../custom-scalars/DateTime';
import TaskStateEnumType from './TaskStateEnumType';
const TaskType = new GraphQLObjectType({
name: 'Task',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLID),
},
name: {
type: new GraphQLNonNull(GraphQLString),
},
completed: {
type: new GraphQLNonNull(GraphQLBoolean),
defaultValue: false
},
state: {
type: new GraphQLNonNull(TaskStateEnumType),
},
progress: {
type: new GraphQLNonNull(GraphQLFloat),
},
taskPriority: {
type: new GraphQLNonNull(GraphQLInt),
},
dueDate: {
type: DateTime,
},
createdAt: {
type: new GraphQLNonNull(DateTime),
},
updatedAt: {
type: DateTime,
},
}),
});
export default TaskType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment