Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
included the preview and previewOne methods
Browse files Browse the repository at this point in the history
  • Loading branch information
umran committed Jun 6, 2019
1 parent ed39d17 commit 5f1ba97
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/graphql/generateGraphqlQueries.js
Expand Up @@ -61,6 +61,50 @@ const createFindField = (schemaKey, schemas, types, resolver) => {
}
}

const createPreviewOneField = (schemaKey, types, resolver) => {
return {
type: types[schemaKey].objectType,
args: {
_id: {
type: new GraphQLNonNull(GraphQLID)
}
},
resolve: async (root, args, context) => {
return await resolver({
method: 'previewOne',
collection: schemaKey,
root,
args,
context
})
}
}
}

const createPreviewField = (schemaKey, schemas, types, resolver) => {
return {
type: new GraphQLNonNull(types[schemaKey].resultsType),
args: Object.keys(schemas[schemaKey].fields).reduce((accumulator, fieldKey) => {
let generatedArg = generateArg(schemas[schemaKey].fields[fieldKey], schemas, types)

if (generatedArg) {
accumulator[fieldKey] = generatedArg
}

return accumulator
}, { _id: { type: GraphQLID }, _options: { type: FindOptions } }),
resolve: async (root, args, context) => {
return await resolver({
method: 'preview',
collection: schemaKey,
root,
args,
context
})
}
}
}

const createSearchField = (schemaKey, types, resolver) => {
return {
type: new GraphQLNonNull(types[schemaKey].resultsType),
Expand Down

0 comments on commit 5f1ba97

Please sign in to comment.