apollo-server

Graphql returns null id for mongoose aggregation query

我的梦境 提交于 2020-01-15 11:43:09
问题 Graphql returns null id for mongoose aggregation query, but works ok other mongoose queries. Here is my mongoose schema: const { Schema } = mongoose; const ObjectId = Schema.Types.ObjectId; const productSchema = new Schema({ _id: ObjectId, price: Number }) const Product = mongoose.model('Product', productSchema, 'Product') Here is my Graphql schema: type Product { id: ID price: String } Graphql normal query: context.Product.findOne() Result with console.log: [ { price: 10, _id:

Graphql returns null id for mongoose aggregation query

你说的曾经没有我的故事 提交于 2020-01-15 11:42:54
问题 Graphql returns null id for mongoose aggregation query, but works ok other mongoose queries. Here is my mongoose schema: const { Schema } = mongoose; const ObjectId = Schema.Types.ObjectId; const productSchema = new Schema({ _id: ObjectId, price: Number }) const Product = mongoose.model('Product', productSchema, 'Product') Here is my Graphql schema: type Product { id: ID price: String } Graphql normal query: context.Product.findOne() Result with console.log: [ { price: 10, _id:

Graphql returns null id for mongoose aggregation query

浪尽此生 提交于 2020-01-15 11:42:51
问题 Graphql returns null id for mongoose aggregation query, but works ok other mongoose queries. Here is my mongoose schema: const { Schema } = mongoose; const ObjectId = Schema.Types.ObjectId; const productSchema = new Schema({ _id: ObjectId, price: Number }) const Product = mongoose.model('Product', productSchema, 'Product') Here is my Graphql schema: type Product { id: ID price: String } Graphql normal query: context.Product.findOne() Result with console.log: [ { price: 10, _id:

How to fix Error: Type “Extra” was defined more than once in apollo-server, using graphql

本小妞迷上赌 提交于 2020-01-07 09:33:28
问题 Problem Hi devs, I have defined two schemas that technically have the same type, but I get the following error: Error: Type "Extra" was defined more than once. Is there a way to solve this problem? My apologies, apollo is new to me and I would really appreciate your help to solve this. Thanks in advance! Schema #1 const {gql} = require('apollo-server'); typeDefs = gql ` extend type Query{ search(q: String!): [Content!]! } type Content{ id: String! title: String! sinopsis: String! poster:

How to fix Error: Type “Extra” was defined more than once in apollo-server, using graphql

拥有回忆 提交于 2020-01-07 09:32:52
问题 Problem Hi devs, I have defined two schemas that technically have the same type, but I get the following error: Error: Type "Extra" was defined more than once. Is there a way to solve this problem? My apologies, apollo is new to me and I would really appreciate your help to solve this. Thanks in advance! Schema #1 const {gql} = require('apollo-server'); typeDefs = gql ` extend type Query{ search(q: String!): [Content!]! } type Content{ id: String! title: String! sinopsis: String! poster:

How to fix the “Name of the mongoose Model” is not a constructor in graphql when mutating

谁说胖子不能爱 提交于 2020-01-05 06:25:32
问题 Mutating data in the graphql playground says the message of Message: Student is not a constructor Error: "TypeError: Student is not a constructor" Student is my Mongoose Model. I've tried reinstalling my node_modules, searching some fix on the github. This is my Mutation Function addStudent: async ( root, { studentId, firstName, lastName, email, password }, { Student } ) => { const newStudent = await new Student({ studentId, firstName, lastName, email, password }).save(); return newStudent; }

How to fix the “Name of the mongoose Model” is not a constructor in graphql when mutating

这一生的挚爱 提交于 2020-01-05 06:24:14
问题 Mutating data in the graphql playground says the message of Message: Student is not a constructor Error: "TypeError: Student is not a constructor" Student is my Mongoose Model. I've tried reinstalling my node_modules, searching some fix on the github. This is my Mutation Function addStudent: async ( root, { studentId, firstName, lastName, email, password }, { Student } ) => { const newStudent = await new Student({ studentId, firstName, lastName, email, password }).save(); return newStudent; }

Apollo GraphQL - Import .graphql schema as typeDefs

跟風遠走 提交于 2020-01-05 03:50:08
问题 With graphql-yoga you can simply import your schema by doing the following: typeDefs: './src/schema.graphql' . Is there a similar way of doing so with apollo-server-express? If there isn't, how does one import the typeDefs from an external .graphql file? 回答1: I found a way of doing this by using grahpql-import which does exactly what I needed. See sample code below: import { ApolloServer } from 'apollo-server-express' import { importSchema } from 'graphql-import' import Query from '.

How to set http status code in GraphQL

末鹿安然 提交于 2020-01-04 05:38:09
问题 I want to set an http status code in my GraphQL authentication query, depending on if auth attempt was successful (200), unauthorised (401) or missing parameters (422). I am using Koa and Apollo and have configured my server like so: const graphqlKoaMiddleware = graphqlKoa(ctx => { return ({ schema, formatError: (err) => ({ message: err.message, status: err.status }), context: { stationConnector: new StationConnector(), passengerTypeConnector: new PassengerTypeConnector(), authConnector: new

Apollo GraphQL Mutation (Object Argument)

白昼怎懂夜的黑 提交于 2020-01-04 05:15:28
问题 So, I'm trying to design my Apollo server. I wanted to create a mutation with an object as a parameter. Here is a snippet of my schema which somehow caused the problem: I thought it was syntactically correct, but I ran into this error: {"errors":[{"message":"Expected Input type."}]} 回答1: You have to declare INPUT_OBJECT to be an input type: input INPUT_OBJECT { field1: String, # etc. } 来源: https://stackoverflow.com/questions/39759988/apollo-graphql-mutation-object-argument