mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 17:41:43 -05:00
Document query and mutation arguments
This commit is contained in:
parent
8100faee85
commit
fec2fc8321
1 changed files with 46 additions and 6 deletions
|
@ -134,17 +134,41 @@ export const createCollection = options => {
|
|||
const queryResolvers = {};
|
||||
// list
|
||||
if (resolvers.list) { // e.g. ""
|
||||
addGraphQLQuery(`${resolvers.list.name}(terms: JSON, offset: Int, limit: Int, enableCache: Boolean): [${typeName}]`, resolvers.list.description);
|
||||
addGraphQLQuery(
|
||||
`${resolvers.list.name}(
|
||||
# A JSON object that contains the query terms used to fetch data
|
||||
terms: JSON,
|
||||
# How much to offset the results by
|
||||
offset: Int,
|
||||
# A limit for the query
|
||||
limit: Int,
|
||||
# Whether to enable caching for this query
|
||||
enableCache: Boolean
|
||||
): [${typeName}]`, resolvers.list.description);
|
||||
queryResolvers[resolvers.list.name] = resolvers.list.resolver.bind(resolvers.list);
|
||||
}
|
||||
// single
|
||||
if (resolvers.single) {
|
||||
addGraphQLQuery(`${resolvers.single.name}(documentId: String, slug: String, enableCache: Boolean): ${typeName}`, resolvers.single.description);
|
||||
addGraphQLQuery(
|
||||
`${resolvers.single.name}(
|
||||
# The document's unique ID
|
||||
documentId: String,
|
||||
# A unique slug identifying the document
|
||||
slug: String,
|
||||
# Whether to enable caching for this query
|
||||
enableCache: Boolean
|
||||
): ${typeName}`, resolvers.single.description);
|
||||
queryResolvers[resolvers.single.name] = resolvers.single.resolver.bind(resolvers.single);
|
||||
}
|
||||
// total
|
||||
if (resolvers.total) {
|
||||
addGraphQLQuery(`${resolvers.total.name}(terms: JSON, enableCache: Boolean): Int`, resolvers.total.description);
|
||||
addGraphQLQuery(
|
||||
`${resolvers.total.name}(
|
||||
# A JSON object that contains the query terms used to fetch data
|
||||
terms: JSON,
|
||||
# Whether to enable caching for this query
|
||||
enableCache: Boolean
|
||||
): Int`, resolvers.total.description);
|
||||
queryResolvers[resolvers.total.name] = resolvers.total.resolver;
|
||||
}
|
||||
addGraphQLResolvers({ Query: { ...queryResolvers } });
|
||||
|
@ -156,17 +180,33 @@ export const createCollection = options => {
|
|||
const mutationResolvers = {};
|
||||
// new
|
||||
if (mutations.new) { // e.g. "moviesNew(document: moviesInput) : Movie"
|
||||
addGraphQLMutation(`${mutations.new.name}(document: ${collectionName}Input) : ${typeName}`, mutations.new.description);
|
||||
addGraphQLMutation(
|
||||
`${mutations.new.name}(
|
||||
# The document to insert
|
||||
document: ${collectionName}Input
|
||||
) : ${typeName}`, mutations.new.description);
|
||||
mutationResolvers[mutations.new.name] = mutations.new.mutation.bind(mutations.new);
|
||||
}
|
||||
// edit
|
||||
if (mutations.edit) { // e.g. "moviesEdit(documentId: String, set: moviesInput, unset: moviesUnset) : Movie"
|
||||
addGraphQLMutation(`${mutations.edit.name}(documentId: String, set: ${collectionName}Input, unset: ${collectionName}Unset) : ${typeName}`, mutations.edit.description);
|
||||
addGraphQLMutation(
|
||||
`${mutations.edit.name}(
|
||||
# The unique ID of the document to edit
|
||||
documentId: String,
|
||||
# An array of fields to insert
|
||||
set: ${collectionName}Input,
|
||||
# An array of fields to delete
|
||||
unset: ${collectionName}Unset
|
||||
) : ${typeName}`, mutations.edit.description);
|
||||
mutationResolvers[mutations.edit.name] = mutations.edit.mutation.bind(mutations.edit);
|
||||
}
|
||||
// remove
|
||||
if (mutations.remove) { // e.g. "moviesRemove(documentId: String) : Movie"
|
||||
addGraphQLMutation(`${mutations.remove.name}(documentId: String) : ${typeName}`, mutations.remove.description);
|
||||
addGraphQLMutation(
|
||||
`${mutations.remove.name}(
|
||||
# The unique ID of the document to delete
|
||||
documentId: String
|
||||
) : ${typeName}`, mutations.remove.description);
|
||||
mutationResolvers[mutations.remove.name] = mutations.remove.mutation.bind(mutations.remove);
|
||||
}
|
||||
addGraphQLResolvers({ Mutation: { ...mutationResolvers } });
|
||||
|
|
Loading…
Add table
Reference in a new issue