Skip to content

Instantly share code, notes, and snippets.

@youngkidwarrior
Last active September 3, 2020 17:58
Show Gist options
  • Save youngkidwarrior/de1fa810288730890b68fedfca239d7a to your computer and use it in GitHub Desktop.
Save youngkidwarrior/de1fa810288730890b68fedfca239d7a to your computer and use it in GitHub Desktop.
import { GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLID } from 'graphql';
import { globalIdField } from 'graphql-relay';
import { ChallengeLoade, } from '../../loaders';
import { GraphQLContext } from '../../TypeDefinition';
import { ChallengeConnection } from '../challenge/ChallengeType';
import { connectionDefinitions, withFilter, connectionArgs } from '../../utils';
import { nodeInterface, registerTypeLoader } from '../node/typeRegister';
import { IUser } from './UserModel';
import { load } from './UserLoader';
const UserType = new GraphQLObjectType<IUser, GraphQLContext>({
name: 'User',
description: 'User data',
fields: () => ({
id: globalIdField('User'),
createdChallenges: {
type: GraphQLNonNull(ChallengeConnection.connectionType),
args: {
...connectionArgs,
},
resolve: async (user, args, context) =>
await ChallengeLoader.loadAll(
context,
withFilter(args, {
creator: user._id,
})
),
},
}),
interfaces: () => [nodeInterface],
});
export const UserConnection = connectionDefinitions({
name: 'User',
nodeType: UserType,
});
registerTypeLoader(UserType, load);
export default UserType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment