Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const graphql = require("graphql");
- const UserType = require("./userType");
- const User = require("../models/User");
- const Project = require("../models/Project");
- const Resource = require("../models/Resource");
- const ProjectType = require("./projectType");
- const {
- GraphQLObjectType,
- GraphQLString,
- GraphQLList,
- } = graphql;
- const ResourceType = new GraphQLObjectType({
- name: "ResourceType",
- fields: () => ({
- id: { type: GraphQLString },
- title: { type: GraphQLString },
- url: { type: GraphQLString },
- project:{
- type:ProjectType,
- resolve(parentValues,args){
- return Project.findById(parentValues.id).populate("resources")
- }
- }
- })
- });
- module.exports=ResourceType;
- const mongoose = require('mongoose');
- const graphql = require('graphql');
- const { GraphQLObjectType, GraphQLList, GraphQLID, GraphQLNonNull } = graphql;
- const ProjectType = require('./../types/projectType');
- const UserType = require('./../types/userType');
- const Project=require("../models/Project");
- const User=require("../models/User");
- const RootQuery=new GraphQLObjectType({
- name:"RootQueryType",
- fields: () => ({
- projects:{
- type:new GraphQLList(ProjectType),
- resolve(parentValues,args,request){
- return Project.find().populate("contributors").populate("resources");
- }
- },
- project:{
- type:ProjectType,
- args:{id:{type:new GraphQLNonNull(GraphQLID)}},
- resolve(parentValue,args,request){
- return Project.findById(args.id).populate("contributors").populate("resources");
- }
- },
- users:{
- type:new GraphQLList(UserType),
- resolve(parentValues,args,request){
- return User.find().populate("projects");
- }
- },
- user:{
- type:UserType,
- args:{id:{type:new GraphQLNonNull(GraphQLID)}},
- resolve(parentValue,args,request){
- return User.findById(args.id).populate("projects")
- }
- },
- })
- })
- module.exports = RootQuery;
- const mongoose = require("mongoose");
- const ProjectType = require("./../types/projectType");
- const UserType = require("./../types/userType");
- const graphql = require("graphql");
- const {
- GraphQLObjectType,
- GraphQLList,
- GraphQLID,
- GraphQLNonNull,
- GraphQLString
- } = graphql;
- const Project = require("../models/Project");
- const User = require("../models/User");
- const mutation = new GraphQLObjectType({
- name: "mutation",
- fields: () => ({
- addUser: {
- type: UserType,
- args: {
- name: { type: new GraphQLNonNull(GraphQLString) },
- username: { type: new GraphQLNonNull(GraphQLString) },
- password: { type: new GraphQLNonNull(GraphQLString) },
- email: { type: new GraphQLNonNull(GraphQLString) },
- githubProfile: { type: new GraphQLNonNull(GraphQLString) }
- },
- resolve(parentValues, args, request) {
- return User.create(args);
- }
- },
- addProject: {
- type: ProjectType,
- args: {
- name: { type: new GraphQLNonNull(GraphQLString) },
- description: { type: new GraphQLNonNull(GraphQLString) },
- image: { type:GraphQLString },
- // contributor:{ type: new GraphQLNonNull(new GraphQLList(GraphQLID))
- contributor:{ type: new GraphQLNonNull(GraphQLID)
- },
- },
- resolve(parentValues, args, request) {
- return Project.create(args);
- }
- }
- })
- });
- module.exports = mutation;
- const graphql = require("graphql");
- const ProjectType = require("./projectType");
- const { GraphQLObjectType, GraphQLString, GraphQLList } = graphql;
- const UserType = new GraphQLObjectType({
- name: "User",
- fields: () => ({
- id: { type: GraphQLString },
- name: { type: GraphQLString },
- githubProfile: { type: GraphQLString },
- username: { type: GraphQLString },
- password: { type: GraphQLString },
- email: { type: GraphQLString },
- projects: {
- type: new GraphQLList(ProjectType),
- resolve(parentValues, args) {
- return User.findById(parentValues.id).populate("projects");
- }
- }
- })
- });
- module.exports = UserType;
- const graphql = require("graphql");
- const UserType = require("./userType");
- const ResourceType = require("./resourceType");
- const User = require("../models/User");
- const Project = require("../models/Project");
- const {
- GraphQLObjectType,
- GraphQLString,
- GraphQLList,
- } = graphql;
- const ProjectType = new GraphQLObjectType({
- name: "ProjectType",
- fields: () => ({
- id: { type: GraphQLString },
- name: { type: GraphQLString },
- description: { type: GraphQLString },
- image: { type: GraphQLString },
- contributors: {
- type: new GraphQLList(UserType),
- resolve(parentValues, args, request) {
- return Project.findContributors(parentValues.id);
- }
- },
- resources:{
- type: new GraphQLList(ResourceType),
- resolve(parentValues, args, request) {
- return Project.findResources(parentValues.id);
- }
- }
- })
- });
- module.exports=ProjectType;
Add Comment
Please, Sign In to add comment