Guest User

Untitled

a guest
Jun 18th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. const graphql = require("graphql");
  2. const UserType = require("./userType");
  3. const User = require("../models/User");
  4. const Project = require("../models/Project");
  5. const Resource = require("../models/Resource");
  6. const ProjectType = require("./projectType");
  7.  
  8. const {
  9. GraphQLObjectType,
  10. GraphQLString,
  11. GraphQLList,
  12. } = graphql;
  13.  
  14.  
  15. const ResourceType = new GraphQLObjectType({
  16. name: "ResourceType",
  17. fields: () => ({
  18. id: { type: GraphQLString },
  19. title: { type: GraphQLString },
  20. url: { type: GraphQLString },
  21. project:{
  22. type:ProjectType,
  23. resolve(parentValues,args){
  24. return Project.findById(parentValues.id).populate("resources")
  25. }
  26. }
  27. })
  28. });
  29.  
  30. module.exports=ResourceType;
  31.  
  32. const mongoose = require('mongoose');
  33. const graphql = require('graphql');
  34. const { GraphQLObjectType, GraphQLList, GraphQLID, GraphQLNonNull } = graphql;
  35.  
  36. const ProjectType = require('./../types/projectType');
  37. const UserType = require('./../types/userType');
  38. const Project=require("../models/Project");
  39. const User=require("../models/User");
  40.  
  41. const RootQuery=new GraphQLObjectType({
  42. name:"RootQueryType",
  43. fields: () => ({
  44. projects:{
  45. type:new GraphQLList(ProjectType),
  46. resolve(parentValues,args,request){
  47. return Project.find().populate("contributors").populate("resources");
  48. }
  49. },
  50. project:{
  51. type:ProjectType,
  52. args:{id:{type:new GraphQLNonNull(GraphQLID)}},
  53. resolve(parentValue,args,request){
  54. return Project.findById(args.id).populate("contributors").populate("resources");
  55. }
  56. },
  57. users:{
  58. type:new GraphQLList(UserType),
  59. resolve(parentValues,args,request){
  60. return User.find().populate("projects");
  61. }
  62. },
  63. user:{
  64. type:UserType,
  65. args:{id:{type:new GraphQLNonNull(GraphQLID)}},
  66. resolve(parentValue,args,request){
  67. return User.findById(args.id).populate("projects")
  68. }
  69. },
  70.  
  71. })
  72. })
  73.  
  74. module.exports = RootQuery;
  75.  
  76. const mongoose = require("mongoose");
  77. const ProjectType = require("./../types/projectType");
  78. const UserType = require("./../types/userType");
  79. const graphql = require("graphql");
  80. const {
  81. GraphQLObjectType,
  82. GraphQLList,
  83. GraphQLID,
  84. GraphQLNonNull,
  85. GraphQLString
  86. } = graphql;
  87.  
  88. const Project = require("../models/Project");
  89. const User = require("../models/User");
  90.  
  91. const mutation = new GraphQLObjectType({
  92. name: "mutation",
  93. fields: () => ({
  94. addUser: {
  95. type: UserType,
  96. args: {
  97. name: { type: new GraphQLNonNull(GraphQLString) },
  98. username: { type: new GraphQLNonNull(GraphQLString) },
  99. password: { type: new GraphQLNonNull(GraphQLString) },
  100. email: { type: new GraphQLNonNull(GraphQLString) },
  101. githubProfile: { type: new GraphQLNonNull(GraphQLString) }
  102. },
  103. resolve(parentValues, args, request) {
  104. return User.create(args);
  105. }
  106. },
  107. addProject: {
  108. type: ProjectType,
  109. args: {
  110. name: { type: new GraphQLNonNull(GraphQLString) },
  111. description: { type: new GraphQLNonNull(GraphQLString) },
  112. image: { type:GraphQLString },
  113. // contributor:{ type: new GraphQLNonNull(new GraphQLList(GraphQLID))
  114. contributor:{ type: new GraphQLNonNull(GraphQLID)
  115. },
  116. },
  117. resolve(parentValues, args, request) {
  118. return Project.create(args);
  119. }
  120. }
  121. })
  122. });
  123.  
  124. module.exports = mutation;
  125.  
  126. const graphql = require("graphql");
  127. const ProjectType = require("./projectType");
  128.  
  129. const { GraphQLObjectType, GraphQLString, GraphQLList } = graphql;
  130.  
  131. const UserType = new GraphQLObjectType({
  132. name: "User",
  133. fields: () => ({
  134. id: { type: GraphQLString },
  135. name: { type: GraphQLString },
  136. githubProfile: { type: GraphQLString },
  137. username: { type: GraphQLString },
  138. password: { type: GraphQLString },
  139. email: { type: GraphQLString },
  140. projects: {
  141. type: new GraphQLList(ProjectType),
  142. resolve(parentValues, args) {
  143. return User.findById(parentValues.id).populate("projects");
  144. }
  145. }
  146. })
  147. });
  148.  
  149. module.exports = UserType;
  150.  
  151. const graphql = require("graphql");
  152. const UserType = require("./userType");
  153. const ResourceType = require("./resourceType");
  154. const User = require("../models/User");
  155. const Project = require("../models/Project");
  156.  
  157. const {
  158. GraphQLObjectType,
  159. GraphQLString,
  160. GraphQLList,
  161. } = graphql;
  162.  
  163. const ProjectType = new GraphQLObjectType({
  164. name: "ProjectType",
  165. fields: () => ({
  166. id: { type: GraphQLString },
  167. name: { type: GraphQLString },
  168. description: { type: GraphQLString },
  169. image: { type: GraphQLString },
  170. contributors: {
  171. type: new GraphQLList(UserType),
  172. resolve(parentValues, args, request) {
  173. return Project.findContributors(parentValues.id);
  174. }
  175. },
  176. resources:{
  177. type: new GraphQLList(ResourceType),
  178. resolve(parentValues, args, request) {
  179. return Project.findResources(parentValues.id);
  180. }
  181. }
  182. })
  183. });
  184.  
  185. module.exports=ProjectType;
Add Comment
Please, Sign In to add comment