Skip to content

Instantly share code, notes, and snippets.

@a7v8x
Last active July 11, 2017 11:18
Show Gist options
  • Save a7v8x/d9de2c04354f92f6b7ec505c99022910 to your computer and use it in GitHub Desktop.
Save a7v8x/d9de2c04354f92f6b7ec505c99022910 to your computer and use it in GitHub Desktop.
import {
GraphQLList,
GraphQLNonNull,
} from 'graphql';
import {
internet,
random,
} from 'faker';
import {
UserType,
UserInputType,
} from './usersTypes';
export const userQueries = {
users: {
type: new GraphQLList(UserType),
resolve: async () => {
const users = await new Promise(resolve =>
setTimeout(() =>
resolve(new Array(10).fill(undefined).map(() => ({
id: random.uuid(),
email: internet.email(),
}))), 100),
);
return users;
},
},
};
export const userMutations = {
createUser: {
type: UserType,
args: {
userPayload: {
type: new GraphQLNonNull(UserInputType),
},
},
resolve: async (rootValue, { userPayload }) => {
const result = await new Promise((resolve) => {
setTimeout(() =>
resolve(Object.assign(userPayload, {
id: random.uuid(),
})), 100);
});
return result;
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment