我正在尝试查询具有ID数组的对象列表.类似于以下SQL查询的东西:
SELECT name FROM events WHERE id IN(1,2,3,...);
Run Code Online (Sandbox Code Playgroud)
我如何在GraphQL中实现这一目标?
是否可以指定GraphQL中的字段应该是黑盒子,类似于Flow具有"任何"类型的方式?我的架构中有一个字段应该能够接受任意值,可以是String,Boolean,Object,Array等.
我想发送没有子节的graphql变异请求
mutation _ {
updateCurrentUser(fullName: "Syava", email: "fake@gmail.com")
}
Run Code Online (Sandbox Code Playgroud)
我正在接受
{
"errors": [
{
"message": "Field \"updateCurrentUser\" of type \"User\" must have a sub selection.",
...
}
]
}
Run Code Online (Sandbox Code Playgroud)
添加{id}请求工作正常,但我不想要
也是架构代码
const userType = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: { type: new GraphQLNonNull(GraphQLString) },
fullName: { type: GraphQLString },
email: { type: GraphQLString },
}),
});
type: userType,
args: {
fullName: { type: GraphQLString },
email: { type: new GraphQLNonNull(emailType) },
password: { type: GraphQLString }, …Run Code Online (Sandbox Code Playgroud) GraphQL中是否有可能具有也是联合的输入类型?
就像是:
const DynamicInputValueType = new GraphQLUnionType({
name: 'DynamicInputType',
types: [GraphQLString, GraphQLFloat, GraphQLInt]
})
Run Code Online (Sandbox Code Playgroud)
但也可以用作突变的输入?
嗨,我正在努力学习GraphQL语言.我有以下代码片段.
// Welcome to Launchpad!
// Log in to edit and save pads, run queries in GraphiQL on the right.
// Click "Download" above to get a zip with a standalone Node.js server.
// See docs and examples at https://github.com/apollographql/awesome-launchpad
// graphql-tools combines a schema string with resolvers.
import { makeExecutableSchema } from 'graphql-tools';
// Construct a schema, using GraphQL schema language
const typeDefs = `
type User {
name: String!
age: Int!
}
type Query {
me: …Run Code Online (Sandbox Code Playgroud) graphql中的AST是什么?我正在使用graphql-js.它对任何事情有何帮助?
任何文档中的任何内容似乎都不能解释AST是什么
我想创建一个可以返回 anArray of Integers或String.
我已经尝试在 form 中使用 union
union CustomVal = [Int] | String,但这会返回错误。
架构声明是:
union CustomValues = [Int] | String
type Data {
name: String
slug: String
selected: Boolean
values: CustomValues
}
Run Code Online (Sandbox Code Playgroud)
错误是:
node_modules/graphql/error/syntaxError.js:24
return new _GraphQLError.GraphQLError('Syntax Error: ' + description, undefined, source, [position]);
Syntax Error: Expected Name, found [
GraphQL request (81:23)
80:
81: union CustomValues = [Int] | String
Run Code Online (Sandbox Code Playgroud)
这可以在graphql中做到吗?如果没有,您能否建议一种替代方法来做到这一点。
我问这个,因为工会文件说 Note that members of a union type need to be concrete …
这是我的代码
模式
gql`
type Query {
user: X!
}
type User {
name: String!
}
type Time {
age: Int!
}
union X = User | Time
`;
Run Code Online (Sandbox Code Playgroud)
解析器
{
X: {
__resolveType: obj => {
if (obj.name) return { name: "Amasia" };
if (obj.age) return { age: 70 };
return null;
}
},
Query: {
user: () => {
return {
name: "Amasia"
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
要求
query {
user{
... on User {
name
}
... on …Run Code Online (Sandbox Code Playgroud) 我现在正在学习GraphQL,在学习教程的过程中,我遇到了一些我无法理解的行为.假设我们已经在模式中定义了类型:
type Link {
id: ID!
url: String!
description: String!
postedBy: User
votes: [Vote!]!
}
Run Code Online (Sandbox Code Playgroud)
由于docs votes: [Vote!]!意味着该字段应该是不可为空的,并且数组本身也应该是不可为空的.但是,在教程的作者显示查询示例之后,对于某些链接,它返回votes字段的空数组.像这样:
{
"url": "youtube.com",
"votes": []
},
{
"url": "agar.io",
"votes": []
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:不是"非可空"在graphQL模式中意味着"空",或者它只是graphQL服务器的某种错误行为(我的意思是它返回任何数组而没有警告应该有一些由于模式) .
谢谢!
我很难理解何时使用GraphQLInterfaceType和GraphQLUnionType.
我有RTFM:
任何人都可以提供一个真实世界的例子,当这些通过我的厚头有用时会有用吗?