apollo-server

Apollo GraphQL Mutation (Object Argument)

两盒软妹~` 提交于 2020-01-04 05:15:10
问题 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

How to parse GraphQL request string into an object

安稳与你 提交于 2020-01-02 03:14:06
问题 I am running Apollo lambda server for GraphQL. I want to intercept the GraphQL query/mutation from the POST request body and parse it so I can find out which query/mutation the request is asking for. The environment is Node.js. The request isn't JSON, it's GraphQL query language. I've looked around to try and find a way to parse this into an object that I can navigate but I'm drawing a blank. The Apollo server must be parsing it somehow to direct the request. Does anyone know a library that

How to create a nested resolver in apollo graphql server

梦想的初衷 提交于 2019-12-31 21:44:09
问题 Given the following apollo server graphql schema I wanted to break these down into separate modules so I don't want the author query under the root Query schema.. and want it separated. So i added another layer called authorQueries before adding it to the Root Query type Author { id: Int, firstName: String, lastName: String } type authorQueries { author(firstName: String, lastName: String): Author } type Query { authorQueries: authorQueries } schema { query: Query } I tried the following..

Accessing Request object in Apollo Server with ExpressJS

扶醉桌前 提交于 2019-12-31 05:41:08
问题 Is there any way of accessing the request object from the underlying express app in Apollo Server 回答1: The context configuration parameter can be either an object, a function that returns the object, or a function that returns a promise to return the object. This function would get the HTTP request as a parameter, and could be defined like so: const apolloServer = new ApolloServer({ schema, context: async ({ req }) => { const something = getSomething(req) return { something } }, })

apollo-server-express CORS issue

大兔子大兔子 提交于 2019-12-31 01:01:28
问题 So I am migrating to apollo-server-express 2.3.3 ( I was using 1.3.6 ) I've followed several guides, making the necessary tweaks but am stuck in a CORS issue. According to the docs you have to use the applyMiddleware function to wire up the apollo server with express. I am currently doing the following: const app = express(); // CORS configuration const corsOptions = { origin: 'http://localhost:3000', credentials: true } app.use(cors(corsOptions)) // Setup JWT authentication middleware app

Why need a server for running GraphQL

北战南征 提交于 2019-12-25 03:16:58
问题 I am totally new in GraphQL. So many things are confusing for me like why i need a server for running GraphQL as why some library doesn't sort out the implementation. As far as i know server is for respond data. So what else it will do for GraphQL. 回答1: GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they

What are the downside to having Query Response Types in GraphQL?

為{幸葍}努か 提交于 2019-12-24 10:55:21
问题 In the Apollo documentation it talks about using Mutation Response Types where you would return a response that included keys for code , success , message , as well as keys for the specific data that was change. i.e. a user. EXAMPLE : interface MutationResponse { code: String! success: Boolean! message: String! } type UpdateUserMutationResponse implements MutationResponse { code: String! success: Boolean! message: String! user: User } We have been using this approach for some time now. We

Apollo server playground not working on heroku (Working Locally)

和自甴很熟 提交于 2019-12-24 06:17:32
问题 I am Trying to deploy run node js application on heroku, it is deployed successfully but playground doesn't seems to work. I came around this solution by setting introspection: true : https://github.com/apollographql/apollo-server/issues/1718 but that also doesn't seems to work. heroku logs My code: package.json { "name": "travelindiaserver", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "clean": "rm -rf build &&

Apollo/GraphQL: How to get nested elements?

我的未来我决定 提交于 2019-12-24 06:04:33
问题 This is an example document of my mongoDB. I need to get the content.en array via Apollo/GraphQL. But the nested object is getting a problem for me. en is the language tag, so it would be great if this could be used as a variable. Data in MongoDB { "_id" : "9uPjYoYu58WM5Tbtf", "content" : { "en" : [ { "content" : "Third paragraph", "timestamp" : 1484939404 } ] }, "main" : "Dn59y87PGhkJXpaiZ" } The graphQL result should be: { "data": { "article": [ { "_id": "9uPjYoYu58WM5Tbtf", "content": [ {

GraphQL how to do a JOIN request instead of many sequential request?

不问归期 提交于 2019-12-24 00:33:15
问题 I have two GraphQL type: type Author { id: String! name: String! } type Book { id: String! author: Author! name: String! } In my database, it is implemented by a foreign key inside the books table: table authors (pseudo code) `id` INTEGER UNSIGNED `name` STRING table books (pseudo code) `id` INTEGER UNSIGNED `author_id` INTEGER UNSIGNED REFERENCE `authors.id` `name` STRING So when I resolve a GraphQL query like: query allTheBooks { id name author { id name } } I would like to do only one