Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created March 19, 2020 20:16
Show Gist options
  • Save sibelius/971edca433f71b36851d8eef6e712a0f to your computer and use it in GitHub Desktop.
Save sibelius/971edca433f71b36851d8eef6e712a0f to your computer and use it in GitHub Desktop.
timestamps to be spread in any GraphQL Object Type
const UserType = new GraphQLObjectType<IUser, GraphQLContext>({
name: 'User',
description: 'User data',
fields: () => ({
id: globalIdField('User'),
...mongooseIDResolver,
name: {
type: GraphQLString,
resolve: user => user.name,
},
email: {
type: GraphQLString,
resolve: user => user.email,
},
...timestamps,
}),
interfaces: () => [nodeInterface],
});
import { GraphQLString } from 'graphql';
export const timestamps = {
createdAt: {
type: GraphQLString,
resolve: obj => obj.createdAt ? obj.createdAt.toISOString() : null,
},
updatedAt: {
type: GraphQLString,
resolve: obj => obj.updatedAt ? obj.updatedAt.toISOString() : null,
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment