Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const connectionType = typeComposer.schemaComposer.createObjectTC({
name,
description: 'A connection to a list of items.',
fields: {
count: {
type: 'Int!',
description: 'Total object count.',
},
pageInfo: {
type: new NonNullComposer(preparePageInfoType(typeComposer.schemaComposer)),
description: 'Information to aid in pagination.',
},
edges: {
type: new NonNullComposer(
new ListComposer(new NonNullComposer(prepareEdgeType(typeComposer)))
),
description: 'Information to aid in pagination.',
},
},
});
return connectionType;
}
export function prepareEdgeType(
typeComposer: ObjectTypeComposer
): ObjectTypeComposer {
const name = `${typeComposer.getTypeName()}Edge`;
if (typeComposer.schemaComposer.has(name)) {
return typeComposer.schemaComposer.getOTC(name);
}
const edgeType = typeComposer.schemaComposer.createObjectTC({
name,
description: 'An edge in a connection.',
fields: {
node: {
type: new NonNullComposer(typeComposer),
description: 'The item at the end of the edge',
},
cursor: {
type: 'String!',
description: 'A cursor for use in pagination',
},
},
});
return edgeType;
}
}
const connectionType = typeComposer.schemaComposer.createObjectTC({
name,
description: 'A connection to a list of items.',
fields: {
count: {
type: 'Int!',
description: 'Total object count.',
},
pageInfo: {
type: new NonNullComposer(preparePageInfoType(typeComposer.schemaComposer)),
description: 'Information to aid in pagination.',
},
edges: {
type: new NonNullComposer(
new ListComposer(new NonNullComposer(prepareEdgeType(typeComposer)))
),
description: 'Information to aid in pagination.',
},
},
});
return connectionType;
}
const name = `${typeComposer.getTypeName()}${upperFirst(resolverName || 'connection')}`;
if (typeComposer.schemaComposer.has(name)) {
return typeComposer.schemaComposer.getOTC(name);
}
const connectionType = typeComposer.schemaComposer.createObjectTC({
name,
description: 'A connection to a list of items.',
fields: {
count: {
type: 'Int!',
description: 'Total object count.',
},
pageInfo: {
type: new NonNullComposer(preparePageInfoType(typeComposer.schemaComposer)),
description: 'Information to aid in pagination.',
},
edges: {
type: new NonNullComposer(
new ListComposer(new NonNullComposer(prepareEdgeType(typeComposer)))
),
description: 'Information to aid in pagination.',
},
},
});
return connectionType;
}