Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * MONGOSE SCHEMA
- * [questions-schema.js]
- */
- import mongoose from 'mongoose';
- const selectSchema = {
- value: String,
- label: String
- };
- const answerSchema = mongoose.Schema({
- createdAt: mongoose.Schema.Types.Date,
- updatedAt: mongoose.Schema.Types.Date,
- answerId: String,
- title: String,
- displayOrder: Number,
- answersImage: String,
- selectText: String,
- notSelectText: String,
- positiveTip: String,
- negativeTip: String,
- recommended: [selectSchema],
- exclude: [selectSchema],
- isPublished: Boolean
- });
- export const questionSchema = mongoose.Schema({
- mongooseId: mongoose.Schema.Types.ObjectId,
- simpleId: String,
- question: String,
- defRecommended: [selectSchema],
- createdAt: mongoose.Schema.Types.Date,
- updatedAt: mongoose.Schema.Types.Date,
- isPublished: Boolean,
- multipleChoice: Boolean,
- noneOfThese: Boolean,
- answers: [answerSchema]
- });
- export const Questions = mongoose.model('questions', questionSchema);
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- /**
- * GRAPHQL TYPE
- * [questions-type.js]
- */
- import {GraphQLString} from 'graphql';
- import MTGQL from 'mongoose-schema-to-graphql';
- import { questionSchema } from './questions-schema';
- let queryConfig = {
- name: 'questionType',
- description: 'Question schema',
- class: 'GraphQLObjectType',
- schema: questionSchema,
- exclude: ['mongooseId']
- };
- let mutationConfig = {
- name: 'questionMutationType',
- description: 'Question Mutation schema',
- class: 'GraphQLObjectType',
- schema: questionSchema,
- exclude: ['mongooseId'],
- props: {
- defRecommended: {type: GraphQLString},
- answers: {type: GraphQLString}
- }
- };
- export const questionType = MTGQL(queryConfig);
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- /**
- * GRAPHQL QUERY OBJECT
- * [schema-queries.js]
- */
- import { questionType } from './questions-type';
- import { Questions } from './questions-schema';
- let queries = new GraphQLObjectType({
- name: 'Query',
- fields: () => ({
- getQuestions: {
- type: new GraphQLList(questionType),
- args: {
- _id: {
- type: GraphQLString
- },
- simpleId: {
- type: GraphQLString
- },
- isPublished: {
- type: GraphQLBoolean
- },
- answerId: {
- type: GraphQLString
- }
- },
- resolve: (_, args) => Questions.find(args)
- },
- })
- });
- export default queries;
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- /**
- * GRAPHQL SCHEMA
- * [schema.js]
- */
- import { GraphQLSchema } from 'graphql/type';
- import queries from './schema-queries';
- import mutations from './schema-mutations';
- const schema = new GraphQLSchema({
- query,
- mutation,
- });
- export default schema;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement