How to use the graphql-compose.schemaComposer.Query function in graphql-compose

To help you get started, we’ve selected a few graphql-compose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github watscho / express-graphql-mongodb-boilerplate / src / graphql / schema.js View on Github external
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,
github thejibz / graphql-compose-mysql / src / schema / index.js View on Github external
// 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: {
github graphql-compose / graphql-compose-json / src / __fixtures__ / Schema.js View on Github external
/* @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;
github nodkz / conf-talks / articles / graphql / schema-build-ways / graphql-compose.js View on Github external
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,
  },
});
github Traversal-Labs / starfleet / bin / passingGQL.js View on Github external
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'),
github vobi-io / api-composer / lib / build-schema.js View on Github external
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()
  }
github Traversal-Labs / starfleet / bin / createGQL.js View on Github external
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'),