Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
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: {
});
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,
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'],
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: {
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: {
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);
});
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',
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',