Last active
September 3, 2020 17:58
-
-
Save youngkidwarrior/de1fa810288730890b68fedfca239d7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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