graphql-js

How to access the value of parent resolver inside a field resolver while using buildSchema?

限于喜欢 提交于 2019-11-28 14:35:38
When we are using graphqlHTTP, the first argument passed to the resolve method is actually the parameters passed by the client query not root this is fine for a query resolver. But for a usecase where field resolver needs to know of a value of the parent, how to achieve this? type Person { name: String, cityId: String, city: City, } In the above scenario I would like where city would be a field resolver, and it needs access to cityId which is a property on parent type. I assume this should have been passed as parameter to the field resolver but that is not the case. Is there a way to achieve

Share common fields between Input and Type in GraphQL

非 Y 不嫁゛ 提交于 2019-11-28 14:31:46
I was wondering if there's a way to share the common fields between Input and Type in GraphQL so that I don't have to define the same set of fields in multiple places. Example: input PersonInput { id: String! name: String address: String } type Person { id: String! name: String address: String } I know Fragment might be a solution, but if my understanding is correct, using Fragment always requires you to put an ON condition which makes it look like this: Fragment PersonCommonFields on Person { ... } There seems to be no way to specify "on Person/PersonInput". GraphQL fragments are for querying

How to get requested fields inside GraphQL resolver?

给你一囗甜甜゛ 提交于 2019-11-28 11:24:46
I am using graphql-tools . After receiving a GraphQL query, I execute a search using ElasticSearch and return the data. However, usually the requested query includes only a few of the possible fields, not all. I want to pass only the requested fields to ElasticSearch. First, I need to get the requested fields. I can already get the whole query as a string. For example, in the resolver, const resolvers = { Query: { async user(p, args, context) { //can print query as following console.log(context.query) } ..... } } It prints as query User { user(id:"111") { id name address } } Is there any way

What is this new syntax gql`string`

ⅰ亾dé卋堺 提交于 2019-11-28 07:20:31
问题 const GET_DOGS = gql` { dogs { id breed } } `; I found this new syntax from here. Can you explain this syntax? Where can I find detail about it? 回答1: It's called a tagged template. Template literals ( `...` ) can be prefixed with a function name . Upon evaluation, this function will be called and the static and dynamic parts of the template literal are passed to the function. Example: function foo(staticParts, dynamicParts) { console.log(staticParts, dynamicParts); } foo`this is a ${42} test`

In Relay, what role do the node interface and the global ID spec play?

徘徊边缘 提交于 2019-11-28 03:27:24
I started out with the relay-starter-kit and also worked my way through the Relay and GraphQL documentation. But there are quite a few areas that are unexplained and mysterious. Seriously I read a lot of documentations everywhere about all these things but couldn't find any satisfying explanations for the following questions: What is this for? I put logging but it never even gets called at all: var {nodeInterface, nodeField} = nodeDefinitions( (globalId) => { var {type, id} = fromGlobalId(globalId); if (type === 'User') { return getUser(id); } else if (type === 'Widget') { return getWidget(id)

When to use GraphQLID instead of GraphQLInt?

家住魔仙堡 提交于 2019-11-27 21:07:05
问题 It is not clear when to use GraphQLID instead of GraphQLInt. Consider the following schema: type User { id: Int! firstName: String! lastName: String! } type Query { user (id: ID!): User } In case of Query.user , it seem to make no difference whether to use GraphQLID or GraphQLInt . In case of User.id , using GraphQLID will cast the input to string. Using GraphQLInt will ensure that the input is an integer. This makes the query and type system inconsistent. The graphql-js spec simply says: A

How to get requested fields inside GraphQL resolver?

一世执手 提交于 2019-11-27 06:06:30
问题 I am using graphql-tools . After receiving a GraphQL query, I execute a search using ElasticSearch and return the data. However, usually the requested query includes only a few of the possible fields, not all. I want to pass only the requested fields to ElasticSearch. First, I need to get the requested fields. I can already get the whole query as a string. For example, in the resolver, const resolvers = { Query: { async user(p, args, context) { //can print query as following console.log

In Relay, what role do the node interface and the global ID spec play?

谁都会走 提交于 2019-11-27 05:08:00
问题 I started out with the relay-starter-kit and also worked my way through the Relay and GraphQL documentation. But there are quite a few areas that are unexplained and mysterious. Seriously I read a lot of documentations everywhere about all these things but couldn't find any satisfying explanations for the following questions: What is this for? I put logging but it never even gets called at all: var {nodeInterface, nodeField} = nodeDefinitions( (globalId) => { var {type, id} = fromGlobalId

How to access the value of parent resolver inside a field resolver while using buildSchema?

一世执手 提交于 2019-11-27 04:49:08
问题 When we are using graphqlHTTP, the first argument passed to the resolve method is actually the parameters passed by the client query not root this is fine for a query resolver. But for a usecase where field resolver needs to know of a value of the parent, how to achieve this? type Person { name: String, cityId: String, city: City, } In the above scenario I would like where city would be a field resolver, and it needs access to cityId which is a property on parent type. I assume this should

Notable differences between buildSchema and GraphQLSchema?

☆樱花仙子☆ 提交于 2019-11-26 22:56:05
Are there any notable differences between the two? Im interested in anything from runtime and startup performance to features and workflow differences. Documentation does a poor job on explaining the difference and when I should use one over the other. Example in both versions: buildSchema const { graphql, buildSchema } = require('graphql'); const schema = buildSchema(` type Query { hello: String } `); const root = { hello: () => 'Hello world!' }; graphql(schema, '{ hello }', root).then((response) => { console.log(response); }); GraphQLSchema const { graphql, GraphQLSchema, GraphQLObjectType,