Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { schemaComposer } = require('graphql-compose')
require('@app/graphql/types')
const { isAuth, isGuest, isUnverfied /* isVerified */ } = require('@app/middleware')
const {
signInValidator,
signUpValidator,
resetPasswordValidator,
newPasswordValidator,
changePasswordValidator,
updateUserValidator
} = require('@app/validator')
const { UserTC } = require('@app/module')
schemaComposer.Query.addFields({
user: UserTC.getResolver('user', [isAuth])
})
schemaComposer.Mutation.addFields({
signIn: UserTC.getResolver('signIn', [isGuest, signInValidator]),
signUp: UserTC.getResolver('signUp', [isGuest, signUpValidator]),
logout: UserTC.getResolver('logout', [isAuth]),
verifyRequest: UserTC.getResolver('verifyRequest', [isAuth, isUnverfied]),
verify: UserTC.getResolver('verify'),
resetPassword: UserTC.getResolver('resetPassword', [isGuest, resetPasswordValidator]),
newPassword: UserTC.getResolver('newPassword', [
isGuest,
newPasswordValidator
]),
changePassword: UserTC.getResolver('changePassword', [
isAuth,
// for obtaining list of post we get current author.id
// and scan and filter all Posts with desired authorId
resolve: author => filter(posts, { authorId: author.id }),
},
postCount: {
type: "Int",
description: "Number of Posts written by Author",
resolve: author => filter(posts, { authorId: author.id }).length,
},
})
// -----------------------------------------------------------------------------
// #4. Declare roots and build GraphQLSchema
// Requests which read data put into Query
schemaComposer.Query.addFields({
posts: {
type: "[Post]",
resolve: () => posts,
},
author: {
type: "Author",
args: { id: "Int!" },
resolve: (_, { id }) => find(authors, { id }),
},
})
// Requests which modify data put into Mutation
schemaComposer.Mutation.addFields({
upvotePost: {
type: "Post",
args: {
/* @flow */
import { schemaComposer } from 'graphql-compose';
import { FilmTC } from './Film';
import { PeopleTC } from './People';
schemaComposer.Query.addFields({
film: FilmTC.getResolver('findById'),
people: PeopleTC.getResolver('findById'),
peopleByUrl: PeopleTC.getResolver('findByUrl'),
peopleByUrls: PeopleTC.getResolver('findByUrlList'),
});
const schema = schemaComposer.buildSchema();
export default schema;
description: 'Article data with related Author data',
fields: {
title: 'String!',
text: 'String',
authorId: 'Int!',
author: {
type: () => AuthorType,
resolve: source => {
const { authorId } = source;
return authors.find(o => o.id === authorId);
},
},
},
});
schemaComposer.Query.addFields({
articles: {
args: {
limit: { type: 'Int', defaultValue: 3 },
},
type: [ArticleType],
resolve: (_, args) => {
const { limit } = args;
return articles.slice(0, limit);
},
},
authors: {
type: [AuthorType],
resolve: () => authors,
},
});
const passingGQL = (model, modelName) => {
const ModelTC = composeWithMongoose(model, customizationOptions);
schemaComposer.Query.addFields({
[modelName+"ById"] : ModelTC.getResolver('findById'),
[modelName+"ByIds"] : ModelTC.getResolver('findByIds'),
[modelName+"One"] : ModelTC.getResolver('findOne'),
[modelName+"Many"] : ModelTC.getResolver('findMany'),
[modelName+"Count"] : ModelTC.getResolver('count'),
[modelName+"Connection"] : ModelTC.getResolver('connection'),
[modelName+"Pagination"] : ModelTC.getResolver('pagination'),
});
schemaComposer.Mutation.addFields({
[modelName+"CreateOne"] : ModelTC.getResolver('createOne'),
[modelName+"CreateMany"] : ModelTC.getResolver('createMany'),
[modelName+"UpdateById"] : ModelTC.getResolver('updateById'),
[modelName+"UpdateOne"] : ModelTC.getResolver('updateOne'),
[modelName+"UpdateMany"] : ModelTC.getResolver('updateMany'),
[modelName+"RemoveById"] : ModelTC.getResolver('removeById'),
resolvers => {
schemaComposer.Query.addFields({})
schemaComposer.Mutation.addFields({})
resolvers
.forEach(resolver => {
const kind = resolver._kind
? `${resolver._kind.charAt(0).toUpperCase()}${resolver._kind.slice(1)}`
: 'Query'
schemaComposer[kind].addFields({
[resolver._name]: resolver._gqlResolver
})
})
return schemaComposer.buildSchema()
}
const createGQL = (model, modelName) => {
const ModelTC = composeWithMongoose(model, customizationOptions);
schemaComposer.Query.addFields({
[modelName+"ById"] : ModelTC.getResolver('findById'),
[modelName+"ByIds"] : ModelTC.getResolver('findByIds'),
[modelName+"One"] : ModelTC.getResolver('findOne'),
[modelName+"Many"] : ModelTC.getResolver('findMany'),
[modelName+"Count"] : ModelTC.getResolver('count'),
[modelName+"Connection"] : ModelTC.getResolver('connection'),
[modelName+"Pagination"] : ModelTC.getResolver('pagination'),
});
schemaComposer.Mutation.addFields({
[modelName+"CreateOne"] : ModelTC.getResolver('createOne'),
[modelName+"CreateMany"] : ModelTC.getResolver('createMany'),
[modelName+"UpdateById"] : ModelTC.getResolver('updateById'),
[modelName+"UpdateOne"] : ModelTC.getResolver('updateOne'),
[modelName+"UpdateMany"] : ModelTC.getResolver('updateMany'),
[modelName+"RemoveById"] : ModelTC.getResolver('removeById'),