graphql-js

Gatsby.js: Filter GraphQL query by nested object property

Deadly 提交于 2019-12-05 10:34:34
I'm working on a news site which will have articles, each with one or multiple respective authors. If you click on an author's name, it will take you to a page displaying their information and a list of articles they have contributed to. So each article has an authors property, which in turn is an array of author objects with properties: full name, slug ( lowercase version of full name with spaces replaced by dashes ), etc. Is it possible to filter the articles by a particular author's slug when defining the query? query authorQuery($slug: String!) { allContentfulArticle(filter: { //not sure

Graphql post body “Must provide query string.”

╄→гoц情女王★ 提交于 2019-12-05 08:46:36
问题 I use Express-graphql middleware. I send the following request in the body line: POST /graphql HTTP/1.1 Host: local:8083 Content-Type: application/graphql Cache-Control: no-cache Postman-Token: d71a7ea9-5502-d5fe-2e36-0ae49c635a29 { testing { pass(id: 1) { idn } } } and have error { "errors": [ { "message": "Must provide query string." } ] } in graphql i can send update in URL. URL string is too short. i must send update model like mutation { update(id: 2, x1: "zazaza", x2: "zazaza", x3:

How to pass total count to the client in pageInfo

流过昼夜 提交于 2019-12-05 03:19:39
I use first after and last before to do pagination. hasNextPage and hasPreviousPage are very useful. But what I need is also the total count so that I can calculate and show things like page 5 of 343 pages on the client. Unfortunately that is not part of pageInfo even though I have the information on the server site. Can you please include a total field in the pageInfo and extend connectionFromArray to take in the total arrayLength like connectionFromArraySlice already does? Thanks pageInfo is designed to represent information about the specific page, whereas the total number of items is

Are there any tools to dynamically generate graphQl schema string?

柔情痞子 提交于 2019-12-05 01:57:55
问题 I will have JSON from a CMS and using the JSON I want to be able to programmatically write a graphQl schema. Without needing to write the string directly. Are there any JavaScript tools to do this? I am referring to the string argument to the buildSchema function: http://graphql.org/code/ 回答1: The json-graphql-server project does that: Take a data JSON as input, infer types and fields from the data, write a schema containing types, queries and mutations, and start a GraphQL server schema

GraphQL: Non-nullable array/list

谁说我不能喝 提交于 2019-12-04 17:26:10
问题 I'm learning GraphQL now and while walking through tutorial I met behavior that I can't understand. Let's say we have defined type in schema: type Link { id: ID! url: String! description: String! postedBy: User votes: [Vote!]! } Due to docs votes: [Vote!]! means that that field should be a non-nullable and array itself should be non-nullable too. But just after that author of tutorial shows example of query and for some of links it returns empty array for votes field. Like this: { "url":

How do I call an asynchronous node.js function from within a GraphQL resolver requiring a return statement?

落爺英雄遲暮 提交于 2019-12-04 05:18:30
The Hello World example provided on graphql.org/graphql-js for creating a simple GraphQL implementation is the following: var { graphql, buildSchema } = require('graphql'); // Construct a schema, using GraphQL schema language var schema = buildSchema(` type Query { hello: String } `); // The root provides a resolver function for each API endpoint var root = { hello: () => { return 'Hello World!'; } }; // Run the GraphQL query '{ hello }' and print out the response graphql(schema, '{ hello }', root).then((response) => { console.log(response); }); I'm trying to run an asynchronous function

In my query, could I use the result of a parameter to get more info in that query?

為{幸葍}努か 提交于 2019-12-03 20:58:21
问题 Forgive my terribly-worded question but here's some code to explain what I'm trying to do ( slug and value are provided outside this query): const query = `{ post(slug: "${slug}") { content createdAt id <--- I want this id for my reply query slug } reply(replyTo: "id") { <--- The second query in question content createdAt id slug } user(id: "${value}") { username } }`; I just got started with GraphQL and I'm loving the fact that I can query multiple databases in one go. It'd be great if I

Are there any tools to dynamically generate graphQl schema string?

北战南征 提交于 2019-12-03 16:47:01
I will have JSON from a CMS and using the JSON I want to be able to programmatically write a graphQl schema. Without needing to write the string directly. Are there any JavaScript tools to do this? I am referring to the string argument to the buildSchema function: http://graphql.org/code/ The json-graphql-server project does that: Take a data JSON as input, infer types and fields from the data, write a schema containing types, queries and mutations, and start a GraphQL server schema based on that. https://github.com/marmelab/json-graphql-server I know of another tool that does just the JSON to

How to execute GraphQL query from server

痴心易碎 提交于 2019-12-03 16:27:31
问题 I am using graphql-express to create an endpoint where I can execute graphql queries in. Although I am using Sequelize with a SQL database it feels wrong to use it directly from the server outside of my graphql resolve functions. How do I go about querying my graphql API from the same server as it was defined in? This is how I set up my graphql endpoint: const express = require('express'); const router = express.Router(); const graphqlHTTP = require('express-graphql'); const gqlOptions = {

Authentication in Relay & GraphQL

≯℡__Kan透↙ 提交于 2019-12-03 15:01:09
问题 I've been working on an application using react and relay, and now I'm stuck on implementing authentication. I know that you can pass value to each graphql request through the context which is available in GraphQL resolves functions. I'm more confused about what to pass for it and how. Is it better to use JSON Web token, passport, something else? And how should I pass the identifier for the user? Basically what I'm asking, What is best suitable for Relay: jwt, passport, something else? And