graphql-js

GraphQL Union and Input Type?

我与影子孤独终老i 提交于 2019-11-30 17:16:30
Is it possible in GraphQL to have an input type that is also a union? Something like: const DynamicInputValueType = new GraphQLUnionType({ name: 'DynamicInputType', types: [GraphQLString, GraphQLFloat, GraphQLInt] }) but also able to be used as a input for a mutation? Artur Nowak As of September 2017, this is not possible. There is an ongoing discussion around this functionality. There is a npm module. I haven't tested. https://www.npmjs.com/package/graphql-union-input-type 来源: https://stackoverflow.com/questions/45288955/graphql-union-and-input-type

How to execute GraphQL query from server

时光毁灭记忆、已成空白 提交于 2019-11-30 12:36:05
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 = { schema: require('./schema') }; router.use('/', graphqlHTTP(gqlOptions)); modules.exports = router;

GraphQL Expected Iterable, but did not find one for field xxx.yyy

那年仲夏 提交于 2019-11-30 03:27:02
I'm currently trying GraphQL with NodeJS and I don't know, why this error occurs with the following query: { library{ name, user { name email } } } I am not sure if the type of my resolveLibrary is right, because at any example I had a look at they used new GraphQL.GraphQLList() , but in my case I really want to return a single user object, not an array of users. My code: const GraphQL = require('graphql'); const DB = require('../database/db'); const user = require('./user').type; const library = new GraphQL.GraphQLObjectType({ name: 'library', description: `This represents a user's library`,

GraphQL Union and Input Type?

梦想的初衷 提交于 2019-11-30 00:41:04
问题 Is it possible in GraphQL to have an input type that is also a union? Something like: const DynamicInputValueType = new GraphQLUnionType({ name: 'DynamicInputType', types: [GraphQLString, GraphQLFloat, GraphQLInt] }) but also able to be used as a input for a mutation? 回答1: As of September 2017, this is not possible. There is an ongoing discussion around this functionality. 回答2: There is a npm module. I haven't tested. https://www.npmjs.com/package/graphql-union-input-type 来源: https:/

what's the difference between parseValue and parseLiteral in GraphQLScalarType

随声附和 提交于 2019-11-29 23:38:50
Looking through the GraphQL documentation for custom scalar types (I'm trying to create my own date type) I'm not sure what the difference between parseValue and parseLiteral are. http://graphql.org/graphql-js/type/#graphqlscalartype The documentation doesn't seem to include any descriptions of what the functions are supposed to do. Can someone let me know what the requirements are? I'm assuming that serialize must serialize the scalar to a string. Is that correct? I'm assuming that parseLiteral is a deserialization of that string to the type? In my case a Date type. However, in the examples -

How do you prevent nested attack on GraphQL/Apollo server?

孤人 提交于 2019-11-29 19:05:26
How do you prevent a nested attack against an Apollo server with a query such as: { authors { firstName posts { title author { firstName posts{ title author { firstName posts { title [n author] [n post] } } } } } } } In other words, how can you limit the number of recursions being submitted in a query? This could be a potential server vulnerability. As of the time of writing, there isn't a built-in feature in GraphQL-JS or Apollo Server to handle this concern, but it's something that should definitely have a simple solution as GraphQL becomes more popular. This concern can be addressed with

What is this new syntax gql`string`

守給你的承諾、 提交于 2019-11-29 13:45:12
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? 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` Tagged templates can be used to create domain specific languages , such as in this example. There are

graphql, union scalar type?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 07:24:36
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? Scalars can't be used as part of unions, since per the specification, unions specifically "represent an object that could be one of a list of GraphQL

When to use GraphQLID instead of GraphQLInt?

感情迁移 提交于 2019-11-29 01:01:31
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 GraphQLScalarType that represents an ID. Is this an implementation detail (e.g. should GraphQL client

what's the difference between parseValue and parseLiteral in GraphQLScalarType

蹲街弑〆低调 提交于 2019-11-28 17:23:26
问题 Looking through the GraphQL documentation for custom scalar types (I'm trying to create my own date type) I'm not sure what the difference between parseValue and parseLiteral are. http://graphql.org/graphql-js/type/#graphqlscalartype The documentation doesn't seem to include any descriptions of what the functions are supposed to do. Can someone let me know what the requirements are? I'm assuming that serialize must serialize the scalar to a string. Is that correct? I'm assuming that