Questions tagged [graphql-js]

The JavaScript reference implementation for GraphQL, a query language created by Facebook for describing data requirements on complex application data models.

1291 questions
15
votes
2 answers

Graphql - How to perform where clause

I am new to graphql and I am struggling with a query. I want to return a user by their email address I have a type defined call V1User and it has the following fields id, email, password, role What needs to change in this query to return a user…
Damien Gallagher
  • 355
  • 1
  • 4
  • 14
15
votes
4 answers

Graphql-Access arguments in child resolvers

I am using apollo-server and apollo-graphql-tools and I have following schema type TotalVehicleResponse { totalCars: Int totalTrucks: Int } type RootQuery { getTotalVehicals(color: String): TotalVehicleResponse } schema { query:…
Manan Vaghasiya
  • 799
  • 10
  • 24
15
votes
2 answers

How to execute GraphQL query from server

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…
Hoffmann
  • 12,871
  • 13
  • 69
  • 87
15
votes
1 answer

Do GraphQL fields support polymorphism based on passed in arguments?

I would like to define the following queries { // return all individuals individuals { id } } // return ONE individual by id individuals(id:"123") { id } } note that the query name is the same, only the parameters are different. Today,…
Olivier Refalo
  • 46,213
  • 20
  • 84
  • 114
15
votes
1 answer

Is there a way to represent an object of key-value pairs in GraphQL

I am using GraphQL in my Node.js application. And I want to store an object that uses keys as a locale short code and values for the string in the corresponding language. (like { en: "Hello", ru: "Привет" } etc.) I want to represent this using…
serge1peshcoff
  • 3,242
  • 8
  • 36
  • 63
15
votes
2 answers

Real world example of GraphQLInterfaceType and GraphQLUnionType

I'm having a hard time understanding when to use GraphQLInterfaceType and GraphQLUnionType. I've RTFMs:…
Matt K
  • 4,314
  • 3
  • 19
  • 33
15
votes
3 answers

Authentication and Access Control with Relay

The official line from Facebook is that Relay is "intentionally agnostic about authentication mechanisms." In all the examples in the Relay repository, authentication and access control are a separate concern. In practice, I have not found a simple…
Dmitry Minkovsky
  • 30,036
  • 20
  • 97
  • 138
14
votes
1 answer

"Abstract type X must resolve to an Object type at runtime for field Query.user with value

this my code schema gql` type Query { user: X! } type User { name: String! } type Time { age: Int! } union X = User | Time `; resolvers { X: { __resolveType: obj => { if (obj.name) return { name: "Amasia" }; …
Jesus
  • 1,026
  • 2
  • 9
  • 24
14
votes
2 answers

What is this new syntax gql`string`

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?
Nicolas S.Xu
  • 10,813
  • 27
  • 63
  • 112
14
votes
3 answers

Is there a way to generate a GraphQL schema from a protobuf?

I have a rather large/complex protobuf definition of an API, and I wonder if there's a convenient tool to automatically generate a textual GraphQL schema and its (nested) types from a subset of this protobuf? I'm using Node.js normally, but I'm open…
Tobi
  • 30,855
  • 7
  • 52
  • 89
13
votes
1 answer

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

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 =…
TheEnvironmentalist
  • 2,200
  • 13
  • 35
13
votes
2 answers

GraphQL pass args to sub resolve

I have a relationship between User and Post. This is how I query the User Posts. const UserType = new GraphQLObjectType({ name: 'User' fields: () => ({ name: { type: GraphQLString }, posts: { type: new…
user6889738
12
votes
2 answers

graphql, how to design input type when there are "add" and "update" mutation?

Here are my requirements: "add" mutation, every field(or called scalar) of BookInput input type should have additional type modifiers "!" to validate the non-null value. Which means when I add a book, the argument must have title and author field,…
slideshowp2
  • 38,463
  • 29
  • 127
  • 255
12
votes
0 answers

GraphQL loop through array and get all results

I'm new to GraphQL. I'm using API's from Amazon and Itunes to get the title (and other information) of a book. I'm returning an object like this: var data = []; data.title = results[0].title; data.author = results[0].author; return data; I can make…
Elvira
  • 1,210
  • 1
  • 18
  • 42
12
votes
1 answer

Relay: How to merge instead of override queries in nested routes?

I cannot navigate to /users in my app, because it doesn`t trigger fetching of all queries that I would expect it should. My app consists of an App component and some components that contain actual content like Dashboard or UserList. There is also…
Michael Hilus
  • 1,316
  • 1
  • 17
  • 37
1 2
3
85 86