How to use the graphql-compose.schemaComposer.createResolver 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-relay / src / __mocks__ / userTC.js View on Github external
},
    limit: {
      name: 'limit',
      type: GraphQLInt,
    },
  },
  resolve: resolveParams => {
    return Promise.resolve({
      recordId: resolveParams.args.input.id,
      record: (resolveParams.args && resolveParams.args.input) || {},
    });
  },
});
userTC.setResolver('manyArgsWithInput', manyArgsWithInputResolver);

export const manyArgsWithoutInputResolver = schemaComposer.createResolver({
  name: 'manyArgsWithoutInput',
  kind: 'mutation',
  type: new GraphQLObjectType({
    name: 'UserPayload',
    fields: {
      record: {
        type: UserType,
      },
    },
  }),
  args: {
    sort: {
      name: 'sort',
      type: GraphQLString,
    },
    limit: {
github graphql-compose / graphql-compose-connection / src / __mocks__ / userTC.js View on Github external
});
  return list;
}

function prepareFilterFromArgs(resolveParams = {}) {
  const args = resolveParams.args || {};
  const filter = { ...args.filter };
  if (resolveParams.rawQuery) {
    Object.keys(resolveParams.rawQuery).forEach(k => {
      filter[k] = resolveParams.rawQuery[k];
    });
  }
  return filter;
}

export const findManyResolver = schemaComposer.createResolver({
  name: 'findMany',
  kind: 'query',
  type: UserType,
  args: {
    filter: filterArgConfig,
    sort: new GraphQLEnumType({
      name: 'SortUserInput',
      values: {
        ID_ASC: { value: { id: 1 } },
        ID_DESC: { value: { id: -1 } },
        AGE_ASC: { value: { age: 1 } },
        AGE_DESC: { value: { age: -1 } },
      },
    }),
    limit: GraphQLInt,
    skip: GraphQLInt,
github graphql-compose / graphql-compose-connection / src / __mocks__ / userTC.js View on Github external
list = filteredUserList(list, prepareFilterFromArgs(resolveParams));

    if (skip) {
      list = list.slice(skip);
    }

    if (limit) {
      list = list.slice(0, limit);
    }

    return Promise.resolve(list);
  },
});
userTC.setResolver('findMany', findManyResolver);

export const countResolver = schemaComposer.createResolver({
  name: 'count',
  kind: 'query',
  type: GraphQLInt,
  args: {
    filter: filterArgConfig,
  },
  resolve: resolveParams => {
    return Promise.resolve(filteredUserList(userList, prepareFilterFromArgs(resolveParams)).length);
  },
});
userTC.setResolver('count', countResolver);

export const sortOptions: ConnectionSortMapOpts = {
  ID_ASC: {
    value: { id: 1 },
    cursorFields: ['id'],
github graphql-compose / graphql-compose-relay / src / __mocks__ / userTC.js View on Github external
type: GraphQLString,
          },
        },
      }),
    },
  },
  resolve: resolveParams => {
    return Promise.resolve({
      recordId: resolveParams.args.input.id,
      record: (resolveParams.args && resolveParams.args.input) || {},
    });
  },
});
userTC.setResolver('createOne', createOneResolver);

export const manyArgsWithInputResolver = schemaComposer.createResolver({
  name: 'manyArgsWithInput',
  kind: 'mutation',
  type: new GraphQLObjectType({
    name: 'UserPayload',
    fields: {
      record: {
        type: UserType,
      },
    },
  }),
  args: {
    input: {
      name: 'input',
      type: new GraphQLInputObjectType({
        name: 'UserInput',
        fields: {
github graphql-compose / graphql-compose-relay / src / __mocks__ / userTC.js View on Github external
nickname: '@nodkz',
      });
    }
    if (args._id.toString() === '2') {
      return Promise.resolve({
        id: 2,
        name: 'Lee',
        nickname: '@leeb',
      });
    }
    return Promise.resolve(null);
  },
});
userTC.setResolver('findById', findByIdResolver);

export const createOneResolver = schemaComposer.createResolver({
  name: 'createOne',
  kind: 'mutation',
  type: new GraphQLObjectType({
    name: 'UserPayload',
    fields: {
      record: {
        type: UserType,
      },
    },
  }),
  args: {
    input: {
      name: 'input',
      type: new GraphQLInputObjectType({
        name: 'UserInput',
        fields: {
github graphql-compose / graphql-compose-pagination / src / __mocks__ / User.js View on Github external
list = filteredUserList(list, prepareFilterFromArgs(resolveParams));

    if (skip) {
      list = list.slice(skip);
    }

    if (limit) {
      list = list.slice(0, limit);
    }

    return Promise.resolve(list);
  },
});
UserTC.setResolver('findMany', findManyResolver);

export const countResolver = schemaComposer.createResolver({
  name: 'count',
  kind: 'query',
  type: 'Int',
  args: {
    filter: filterArgConfig,
  },
  resolve: resolveParams => {
    return Promise.resolve(filteredUserList(userList, prepareFilterFromArgs(resolveParams)).length);
  },
});
UserTC.setResolver('count', countResolver);
github graphql-compose / graphql-compose-pagination / src / __mocks__ / User.js View on Github external
});
  return list;
}

function prepareFilterFromArgs(resolveParams = {}) {
  const args = resolveParams.args || {};
  const filter = { ...args.filter };
  if (resolveParams.rawQuery) {
    Object.keys(resolveParams.rawQuery).forEach(k => {
      filter[k] = resolveParams.rawQuery[k];
    });
  }
  return filter;
}

export const findManyResolver = schemaComposer.createResolver({
  name: 'findMany',
  kind: 'query',
  type: UserTC,
  args: {
    filter: filterArgConfig,
    sort: schemaComposer.createEnumTC({
      name: 'SortUserInput',
      values: {
        ID_ASC: { value: { id: 1 } },
        ID_DESC: { value: { id: -1 } },
        AGE_ASC: { value: { age: 1 } },
        AGE_DESC: { value: { age: -1 } },
      },
    }),
    limit: 'Int',
    skip: 'Int',
github graphql-compose / graphql-compose-relay / src / __mocks__ / userTC.js View on Github external
id: {
      type: GraphQLInt,
    },
    name: {
      type: GraphQLString,
    },
    nickname: {
      type: GraphQLString,
    },
  },
});

export const userTC = schemaComposer.createObjectTC(UserType);
userTC.setRecordIdFn(obj => obj.id);

export const findByIdResolver = schemaComposer.createResolver({
  name: 'findById',
  kind: 'query',
  type: UserType,
  args: {
    _id: {
      name: '_id',
      type: new GraphQLNonNull(GraphQLInt),
    },
  },
  resolve: resolveParams => {
    const args = resolveParams.args || {};
    if (args._id.toString() === '1') {
      return Promise.resolve({
        id: 1,
        name: 'Pavel',
        nickname: '@nodkz',