我的目标是能够在 GraphQL 查询中传递字符串对象。
目标:
{
accounts (filter:
'{"fieldName": "id",
"fieldValues":["123"],
"filterType":"in"}'){
id
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
"Syntax Error GraphQL request (1:22) Unexpected single quote character ('), did you mean to use a double quote (\")?"
Run Code Online (Sandbox Code Playgroud)
问题是 GraphQL 似乎不接受用单引号括起来的字符串。
在对象内部使用单引号是不可能的,因为这需要对编译这些对象的客户端进行重大更改。
例子:
{
"fieldName": "id",
"fieldValues":["123"],
"filterType":"in"
}
Run Code Online (Sandbox Code Playgroud)
架构:
accounts: {
type: new GraphQLList(accountType),
args: {
id: { type: GraphQLString },
status: { type: GraphQLString },
filter: { type: GraphQLString },
sort: { type: GraphQLString },
},
resolve: (root, args, { loaders }) …Run Code Online (Sandbox Code Playgroud) 我的目标是能够在 GraphQL 查询中将对象作为参数传递。
目标:
{
accounts (filter:
{"fieldName": "id",
"fieldValues":["123"],
"filterType":"in"}){
id
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
"message": "filterType fields must be an object with field names as keys or a function which returns such an object."
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方法,但这似乎是最接近潜在解决方案的方法。
架构:
const filterType = new GraphQLObjectType ({
name: 'filterType',
fields: {
fieldName: { type: GraphQLString },
fieldValues: { type: GraphQLString },
filterType: { type: GraphQLString },
}
})
const QueryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
accounts: {
type: new GraphQLList(accountType), …Run Code Online (Sandbox Code Playgroud) 尝试将一个组件导入到第二个组件时,我收到以下错误。
“InputComponent”类型中缺少属性“prototype”,但“typeof InputComponent”类型中需要属性“prototype”。TS(2741)
测试.ts
class InputComponent {
add():number{
return 1 + 1
}
}
class Example {
public input: typeof InputComponent;
constructor(Input: typeof InputComponent) {
this.input = new Input();
}
}
class Example2 {
public input: typeof InputComponent;
constructor(Input: typeof InputComponent = InputComponent) {
this.input = new Input();
}
}Run Code Online (Sandbox Code Playgroud)
这是错误和沙箱的屏幕截图。