apollo-server

Log apollo-server GraphQL query and variables per request

别说谁变了你拦得住时间么 提交于 2019-11-29 09:32:17
问题 When using apollo-server 2.2.1 or later, how can one log, for each request, the query and the variables? This seems like a simple requirement and common use case, but the documentation is very vague, and the query object passed to formatResponse no longer has the queryString and variables properties. 回答1: Amit's answer works (today), but IMHO it is a bit hacky and it may not work as expected in the future, or it may not work correctly in some scenarios. For instance, the first thing that I

Array of Objects Apollo Server and post from react

一世执手 提交于 2019-11-28 14:35:16
So i'm trying to figure out how to pass an array of objects from a POST request to apollo server on AWS lambda. I've checked this out but it's not the same problem Array of objects convert into object of objects when I use Apollo The post request looks like this... api.post('query', { query : `mutation {saveNewItem(description: "${description}", specials: ${JSON.stringify(specials)}){name}}`}) // comment to get rid of silly scroll bar overlapping code Schema looks like this... const { gql } = require('apollo-server-lambda') const typeDefs = gql` type ShoppingItem { description: String specials

Apollo/GraphQL field type for object with dynamic keys

怎甘沉沦 提交于 2019-11-28 10:04:01
Let's say my graphql server wants to fetch the following data as JSON where person3 and person5 are some id's: "persons": { "person3": { "id": "person3", "name": "Mike" }, "person5": { "id": "person5", "name": "Lisa" } } Question : How to create the schema type definition with apollo? The keys person3 and person5 here are dynamically generated depending on my query (i.e. the area used in the query). So at another time I might get person1 , person2 , person3 returned. As you see persons is not an Iterable, so the following won't work as a graphql type definition I did with apollo: type Person {

Are mutation methods required to be on the top level?

元气小坏坏 提交于 2019-11-27 05:22:25
All docs and tutorials usually show simple examples of mutations that look like this: extend type Mutation { edit(postId: String): String } But this way the edit method has to be unique across all entities, which to me seems like not a very robust way to write things. I would like to describe mutation similar to how we describe Queries, something like this: type PostMutation { edit(postId: String): String } extend type Mutation { post: PostMutation } This seems to be a valid schema (it compiles and I can see it reflected in the generated graph-i-ql docs). But I can't find a way to make

How to know which fields were requested in a GraphQL query?

寵の児 提交于 2019-11-27 04:53:40
问题 I have written a GraphQL query which like the one below: { posts { author { comments } comments } } I want to know how can I get the details about the requested child fields inside the posts resolver. I want to do it to avoid nested calls of resolvers. I am using ApolloServer's DataSource API. I can change the API server to get all the data at once. I am using ApolloServer 2.0 and any other ways of avoiding nested calls are also welcome. 回答1: You'll need to parse the info object that's passed

Apollo/GraphQL field type for object with dynamic keys

我只是一个虾纸丫 提交于 2019-11-26 16:44:27
问题 Let's say my graphql server wants to fetch the following data as JSON where person3 and person5 are some id's: "persons": { "person3": { "id": "person3", "name": "Mike" }, "person5": { "id": "person5", "name": "Lisa" } } Question : How to create the schema type definition with apollo? The keys person3 and person5 here are dynamically generated depending on my query (i.e. the area used in the query). So at another time I might get person1 , person2 , person3 returned. As you see persons is not

Are mutation methods required to be on the top level?

人走茶凉 提交于 2019-11-26 11:34:08
问题 All docs and tutorials usually show simple examples of mutations that look like this: extend type Mutation { edit(postId: String): String } But this way the edit method has to be unique across all entities, which to me seems like not a very robust way to write things. I would like to describe mutation similar to how we describe Queries, something like this: type PostMutation { edit(postId: String): String } extend type Mutation { post: PostMutation } This seems to be a valid schema (it

Why does a GraphQL query return null?

佐手、 提交于 2019-11-25 22:15:44
问题 I have an graphql / apollo-server / graphql-yoga endpoint. This endpoint exposes data returned from a database (or a REST endpoint or some other service). I know my data source is returning the correct data -- if I log the result of the call to the data source inside my resolver, I can see the data being returned. However, my GraphQL field(s) always resolve to null. If I make the field non-null, I see the following error inside the errors array in the response: Cannot return null for non