Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. /**
  2. * MONGOSE SCHEMA
  3. * [questions-schema.js]
  4. */
  5. import mongoose from 'mongoose';
  6.  
  7. const selectSchema = {
  8. value: String,
  9. label: String
  10. };
  11.  
  12. const answerSchema = mongoose.Schema({
  13. createdAt: mongoose.Schema.Types.Date,
  14. updatedAt: mongoose.Schema.Types.Date,
  15. answerId: String,
  16. title: String,
  17. displayOrder: Number,
  18. answersImage: String,
  19. selectText: String,
  20. notSelectText: String,
  21. positiveTip: String,
  22. negativeTip: String,
  23. recommended: [selectSchema],
  24. exclude: [selectSchema],
  25. isPublished: Boolean
  26. });
  27.  
  28. export const questionSchema = mongoose.Schema({
  29. mongooseId: mongoose.Schema.Types.ObjectId,
  30. simpleId: String,
  31. question: String,
  32. defRecommended: [selectSchema],
  33. createdAt: mongoose.Schema.Types.Date,
  34. updatedAt: mongoose.Schema.Types.Date,
  35. isPublished: Boolean,
  36. multipleChoice: Boolean,
  37. noneOfThese: Boolean,
  38. answers: [answerSchema]
  39. });
  40.  
  41. export const Questions = mongoose.model('questions', questionSchema);
  42.  
  43.  
  44. ////////////////////////////////////////////////////////////////////////////////////////////////////
  45. /**
  46. * GRAPHQL TYPE
  47. * [questions-type.js]
  48. */
  49. import {GraphQLString} from 'graphql';
  50. import MTGQL from 'mongoose-schema-to-graphql';
  51. import { questionSchema } from './questions-schema';
  52.  
  53. let queryConfig = {
  54. name: 'questionType',
  55. description: 'Question schema',
  56. class: 'GraphQLObjectType',
  57. schema: questionSchema,
  58. exclude: ['mongooseId']
  59. };
  60. let mutationConfig = {
  61. name: 'questionMutationType',
  62. description: 'Question Mutation schema',
  63. class: 'GraphQLObjectType',
  64. schema: questionSchema,
  65. exclude: ['mongooseId'],
  66. props: {
  67. defRecommended: {type: GraphQLString},
  68. answers: {type: GraphQLString}
  69. }
  70. };
  71.  
  72. export const questionType = MTGQL(queryConfig);
  73.  
  74. ////////////////////////////////////////////////////////////////////////////////////////////////////
  75. /**
  76. * GRAPHQL QUERY OBJECT
  77. * [schema-queries.js]
  78. */
  79. import { questionType } from './questions-type';
  80. import { Questions } from './questions-schema';
  81.  
  82. let queries = new GraphQLObjectType({
  83. name: 'Query',
  84. fields: () => ({
  85. getQuestions: {
  86. type: new GraphQLList(questionType),
  87. args: {
  88. _id: {
  89. type: GraphQLString
  90. },
  91. simpleId: {
  92. type: GraphQLString
  93. },
  94. isPublished: {
  95. type: GraphQLBoolean
  96. },
  97. answerId: {
  98. type: GraphQLString
  99. }
  100. },
  101. resolve: (_, args) => Questions.find(args)
  102. },
  103. })
  104. });
  105.  
  106. export default queries;
  107.  
  108. ////////////////////////////////////////////////////////////////////////////////////////////////////
  109. /**
  110. * GRAPHQL SCHEMA
  111. * [schema.js]
  112. */
  113. import { GraphQLSchema } from 'graphql/type';
  114. import queries from './schema-queries';
  115. import mutations from './schema-mutations';
  116.  
  117. const schema = new GraphQLSchema({
  118. query,
  119. mutation,
  120. });
  121.  
  122. export default schema;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement