graphql-js

GraphQL schema equivalent of this Json?

流过昼夜 提交于 2019-12-11 15:12:30
问题 I'm newbie to GraphQL, and was wondering if someone could help me figure out what is the equivalent of below JSON into GraphQL schema: [ { "id": "1", "name": "A", "fldDef": [ { "name": "f1", "type": "str", "opt": false }, { "name": "f2", "type": "bool" }] }, { "id": "2", "name": "B", "fldDef": [ { "name": "f3", "type": "str", "opt": true }, { "name": "f4", "type": "str", "opt": true }] } ] So far I managed to map above response to below object: public class FldDef { private String name, type;

How can I use isValidJSValue to validate a query variable in my client code?

試著忘記壹切 提交于 2019-12-11 14:47:08
问题 I'm writing client-side code for an app that will query a GraphQL server. In a couple of places in my code, I'm passing around data that will eventually get turned into a query variable, so it needs to validate against a specific GraphQLInputType in my schema. On looking into some of the utilities that graphql-js provides, it looks like the isValidJSValue checker is exactly what I'm looking for, and its comments even mention that it's intended to be used to do just that. The issue is that I

Type gql-tag in TypeScript

我与影子孤独终老i 提交于 2019-12-11 13:19:12
问题 I am working with GraphQL and I want to have strict typing in gql . Is it possible to make result variable to be shape of ResultData i.e. with the latest version of TypeScript. It is only about typing, not about runtime. interface Data { one: string; two: number; three: { four: string; five: { six: Date; }; }; } // true means that this field must be added to query type RecursivePartial<T> = {[P in keyof T]?: RecursivePartial<T[P]> | true}; function gql<T>(fields: RecursivePartial<T>) { //

When to use `parent` and when to use `root` as first argument in a GraphQL-resolver function

坚强是说给别人听的谎言 提交于 2019-12-11 07:05:15
问题 I've seen some tutorials and examples out there who are sometimes using parent and sometimes using root for their first argument in a graphql resolver. What would be the correct naming in which situation and why? For example(nodejs): signup: (root, args, context, info) => signup(root, args, context, info) vs signup: (parent, args, context, info) => signup(parent, args, context, info) or in the function which does the signup: const signup(root, args, context, info) = { // do magic stuff } vs

info argument is empty in Apollo GraphQL resolver type signature

*爱你&永不变心* 提交于 2019-12-11 06:33:41
问题 I'm working on this library https://github.com/ilyaskarim/wertik-js called Wertik JS to make GraphQL + Rest API more easily, In resolvers, when I console log info , it shows undefined. For each module, I have created dynamic resolvers to make things more easy for developers who will use this library. let object = { create: async (_:any, args:any, context:any,info: any) => { console.log(info); // This will be undefined let v = await validate(validations.create,args.input); let {success} = v;

Submit an array of objects as a query variable in graphQL

蓝咒 提交于 2019-12-11 05:21:49
问题 How can I structure the query parameters a graphQL mutation when one of the fields is an array of objects? When I hard-code the mutation this is valid and works: mutation{ submitResponse(user: "1234", responses: [{ answerId: "wmtBCWtkSeDs5meBe", selected: false}, { answerId: "wmtBCWtkSeDs5meBz", selected: true}]) { id } } I can't for the life of me figure out how to pass in query parameters for the responses array of objects. How can I define the type of each field in the object. This is what

How to Convert GraphQLSchema Object to Type Definitions

不羁的心 提交于 2019-12-11 04:18:15
问题 Let's say i have a GraphQL Schema like: type author { id: Int name: String rating: Int } You can use this type definition to generate an executable schema that can be queried on. But in case i don't have the above type definitions, but only have GraphQLSchema object obtained through the introspection query, how do i generate the above type definitions? I checked out graphql/utilities which had a printSchema method, that accepts a GraphQLSchema object and prints a string. But i can't seem to

Bad request while trying to access Github's v4 API with graphql.js

亡梦爱人 提交于 2019-12-11 04:07:05
问题 I am trying to retrieve some data from Github's GraphQL API using graphql.js library. var graph = graphql("https://api.github.com/graphql", { method: "POST", headers: { "Authorization": "Bearer <my-token-here>", "Content-Type": "application/json" }, fragments: { rateLimitInfo: "on RateLimit {cost,remaining,resetAt}" } }); graph(` query repo($name: String!, $owner: String!){ repository(name:$name, owner:$owner){ id } } `,{ name: "freeCodeCamp", owner: "freeCodeCamp" }).then(function(response){

graphql multiple mutations using prior mutation return results?

只愿长相守 提交于 2019-12-11 02:29:47
问题 I understand that mutations are sequential, so it makes sense to me that if Mutation 1 creates an entity and returns an id, that Mutation 2 should have access to that id. However I don't see any examples online and can't seem to get it to work. I see that people say you need to handle this in the resolve function of your route but it seems like extra unnecessary code if I can get this in just the query. For example I have the following where accounts belong to clients and hence need the

Sequelize on GraphQL update not return anything

烂漫一生 提交于 2019-12-11 00:14:25
问题 GraphQL return null using Sequelize update. updatePerson: { type: Person, args: { value: { type: UpdatePersonInputType }, where: { type: WhereUpdatePersonInputType } }, resolve(_, args) { return Db.models.persons.update( args.value, { where: args.where }); } }, Here my request using GraphiQL mutation { updatePerson(value: {firstName: "John", lastName: "Doe", email: "johndoe@example.com"}, where: {id: 1}){ id firstName lastName email } } and this the result { "data": { "updatePerson": { "id":