graphql-js

How to query list of objects with array as an argument in GraphQL

做~自己de王妃 提交于 2019-12-18 14:38:30
问题 I'm trying to query a list of objects having array of IDs. Something similar to following SQL query: SELECT name FROM events WHERE id IN(1,2,3,...); How do I achieve this in GraphQL? 回答1: You can definitely query with an array of values! Here's what the query itself would look like: { events(containsId: [1,2,3]) { ... } } And the type would look something like: const eventsType = new GraphQLObjectType({ name: 'events', type: // your type definition for events, args: { containsId: new

graphql, union scalar type?

♀尐吖头ヾ 提交于 2019-12-17 16:37:38
问题 The payload field can be Int or String scalar type. when I write it like union type: const schema = ` input QuickReply { content_type: String title: String payload: Int | String image_url: String } ` I got an error: GraphQLError: Syntax Error GraphQL request (45:18) Expected Name, found | 44: title: String 45: payload: Int | String ^ 46: image_url: String It seems GraphQL does not support union scalar type. So, how can I solve this situation? 回答1: Scalars can't be used as part of unions,

GraphQL Blackbox / “Any” type?

浪尽此生 提交于 2019-12-17 02:23:11
问题 Is it possible to specify that a field in GraphQL should be a blackbox, similar to how Flow has an "any" type? I have a field in my schema that should be able to accept any arbitrary value, which could be a String, Boolean, Object, Array, etc. 回答1: @mpen's answer is great, but I opted for a more compact solution: const { GraphQLScalarType } = require('graphql') const { Kind } = require('graphql/language') const ObjectScalarType = new GraphQLScalarType({ name: 'Object', description: 'Arbitrary

Write dynamic schema for return same result in Graphql

烂漫一生 提交于 2019-12-16 18:03:12
问题 Currently this schema working properly and give required result type Personal{ userId:String name: String email: String } type Contact{ mobile_no:String email:String } type Address{ address:String lat:String long:String } getContact(userId: String): Contact getPersonal(userId: String): Personal getAddress(userId: String): Address But I want to return type Response { status: Boolean message: String data: [] } Return data with status and message key where data hold an array of Contact, Personal

GraphQL fetch data at Query level results in redundant/useless request

人走茶凉 提交于 2019-12-14 03:05:51
问题 We are implementing GraphQL service, which stands in front of several backend microservices. For example, we have a Product and each product has a list of history orders. Our backend server provides two REST APIs, one for product detail data, the other returns the history order list of a product. Our client app has two pages: one is the product detail page, the other is the history order list of a product. So, in the product detail page, we can only retrieve the detail data of the product,

How to return both error and data in a graphql resolver?

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:25:35
问题 I was thinking about ways of implementing graphql response that would contain both an error and data. Is it possible to do so without creating a type that would contain error ? e.g. Mutation addMembersToTeam(membersIds: [ID!]! teamId: ID!): [Member] adds members to some team. Suppose this mutation is called with the following membersIds : [1, 2, 3] . Members with ids 1 and 2 are already in the team, so an error must be thrown that these members cannot be added, but member with an id 3 should

Graphql requiring module outside vs inside GraphQLObjectType

天大地大妈咪最大 提交于 2019-12-12 18:04:04
问题 May be the title is not suitable with my problem but let me explain my scenario. I am working with Graphql schema.Here is my initial schema.js file https://github.com/sany2k8/graphql-udemy/blob/master/schema/schema.js and it was working fine then I decided to split it into different small files e.g root_query_type.js , mutation.js , user_type.js and company_type.js . All the files are exported as module and required circularly. For example - user_type.js const graphql = require('graphql');

Apollo readQuery Fails Even Though Target Object is Present?

﹥>﹥吖頭↗ 提交于 2019-12-12 10:11:28
问题 I'm working on a call to readQuery. I'm getting an error message: modules.js?hash=2d0033b4773d9cb6f118946043f7a3d4385825fe:25847 Error: Can't find field resolutions({"id":"Resolution:DHSzPa8bvPCDjuAac"}) on object (ROOT_QUERY) { "resolutions": [ { "type": "id", "id": "Resolution:AepgCCio9KWGkwyMC", "generated": false }, { "type": "id", "id": "Resolution:DHSzPa8bvPCDjuAac", // <==ID I'M SEEKING "generated": false } ], "user": { "type": "id", "id": "User:WWv57KsvqWeAoBNHY", "generated": false }

GraphQL Schema to handle mixed types

岁酱吖の 提交于 2019-12-12 08:07:24
问题 I've recently started to research the possibility of using GraphQL for requesting dynamic data configurations. The very first thing that jumps out at me is the strongly-typed concept of GraphQL. Is there a way for GraphQL schemas to handle arrays of mixed type objects? I would greatly appreciate either an explanation or possibly a reference I can read over. I am currently working with GraphQL with Node.js but a later implementation will be out of a Java Container. All data will be JSON pulled

Is there a way to avoid circular type dependencies in GraqhQL?

我只是一个虾纸丫 提交于 2019-12-12 02:14:37
问题 Consider the main SWAPI example for the reference implementation: https://github.com/graphql/swapi-graphql // film.js import PersonType from './person'; // person.js import FilmType from './film'; That's all over the place. Are these circular deps an acceptable practice? Are there any good patterns for avoiding this? It seems bad to include problematic practices in the definitive demo for GraphQL. 回答1: In case of GraphQL it is not bad practice, they even prepared a solution for this situation