How to use the graphql-compose.composeType 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 graphql-compose / graphql-compose / src / metaApiProposal.js View on Github external
password: String,
  dob: String,
  createdAt: Date,
  updatedAt: Date,
});

import { composeType, composeField, composeResolve, composeInterface, composeStorage } from 'graphql-compose';
import { description, only, remove, restrict, add } from 'graphql-compose/type';
import { composeTypeFromMongoose } from 'graphql-compose-mongoose';
import { GraphQLString } from 'graphql';



//---------- TYPE MODIFICATORS

composeType('User',
  composeTypeFromMongoose(UserMongooseModel),
     addResolverParam('model', UserMongooseModel), // internally added by `composeTypeFromMongoose`
  composeInterface('Timestable'), // internally call composeStorage.Interfaces.get('Timestable')
  description('User model description'),
  only(['myName', 'surname']), // get only described fields
  remove(['stats', 'password']), // ... or leave others, and remove just listed here
  rename({
    myName: 'name',
    surname: 'lastname',
  }),
  restrict({
    hasAccess: (source, args, context, info) => {
      return context.isAdmin;
    },
    fields: ['name', 'dob'],
  }),
github graphql-compose / graphql-compose / src / metaApiProposal.js View on Github external
changeValue({
    name: ({ source, args, context, info }) => `${source.name} modified`,
  }),

  // example of custom type-middleware
  next => typeConfig => {
    const gqType = next(typeConfig);
    return gqType;
  },
);



//---------- INHERITANCE

composeType('SuperUser',
  cloneType('User'),
  add('isSuperUserType',
    {
      type: GraphQLBoolean,
      resolve: () => true,
    }
  )
);



//---------- FIELD RESOLVERS

composeType('User',
  add(
    'friends',
github graphql-compose / graphql-compose / src / metaApiProposal.js View on Github external
composeType('SuperUser',
  cloneType('User'),
  add('isSuperUserType',
    {
      type: GraphQLBoolean,
      resolve: () => true,
    }
  )
);



//---------- FIELD RESOLVERS

composeType('User',
  add(
    'friends',
    composeField(
      // custom field middleware
      next => fieldConfig => {
        const gqField = next(fieldConfig);
        return gqField;
      },
      description('List of friends'),
      addArg('gender', {}),
      composeResolve(
        argEval(({ source }) => ({ frendId: source._id })),
        resolveList('User'),

        // example of custom resolve-middleware
        next => resolveParams => {
github graphql-compose / graphql-compose / src / metaApiProposal.js View on Github external
//---------- MUTATIONS (in progress, not ready)

composeType('UserInput',
  cloneType('User'),
  makeInputType(),
  remove(['id'])
);

composeType('RootMutation',
  add('createUser', composeType('User').queryById)
);


//----------- ROOT CONSTRUCTOR  (in progress, not ready)

composeType('RootQuery',
  add('user', composeType('User').queryById),
  add('userList', composeType('User').queryList),
  add('userConnection', composeType('User').queryConnection),
  add('superUser', composeType('SuperUser').queryById)
);



//----------- INTERFACES

composeInterface('Timestable',
  description('Timestable interface for types, which have fields with creation and modification time'),
  add('createdAt', {
    type: GraphQLDate,
  }),
  add('updatedAt', {
github graphql-compose / graphql-compose / src / metaApiProposal.js View on Github external
'User',
  'byId',
  addIdArg,
  addResolverParam('DL', new DataLoader(keys => myBatchGetUsers(keys))),
  addResolve(
    (pluginParams, loaderParams, { source, args, context, info }) => {
      return loaderParams.DL.load(args.id);
    }
  ),
);



//---------- MUTATIONS (in progress, not ready)

composeType('UserInput',
  cloneType('User'),
  makeInputType(),
  remove(['id'])
);

composeType('RootMutation',
  add('createUser', composeType('User').queryById)
);


//----------- ROOT CONSTRUCTOR  (in progress, not ready)

composeType('RootQuery',
  add('user', composeType('User').queryById),
  add('userList', composeType('User').queryList),
  add('userConnection', composeType('User').queryConnection),
github graphql-compose / graphql-compose / src / metaApiProposal.js View on Github external
return loaderParams.DL.load(args.id);
    }
  ),
);



//---------- MUTATIONS (in progress, not ready)

composeType('UserInput',
  cloneType('User'),
  makeInputType(),
  remove(['id'])
);

composeType('RootMutation',
  add('createUser', composeType('User').queryById)
);


//----------- ROOT CONSTRUCTOR  (in progress, not ready)

composeType('RootQuery',
  add('user', composeType('User').queryById),
  add('userList', composeType('User').queryList),
  add('userConnection', composeType('User').queryConnection),
  add('superUser', composeType('SuperUser').queryById)
);



//----------- INTERFACES