小编JTA*_*TAN的帖子

GraphQL-js Node/Express:如何在 GraphQL 查询中传递字符串对象?

我的目标是能够在 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)

node.js express graphql-js

6
推荐指数
1
解决办法
3477
查看次数

GraphQL.js Node/Express:如何将对象作为 GraphQL 查询参数传递

我的目标是能够在 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)

node.js express graphql

5
推荐指数
2
解决办法
6715
查看次数

Typescript 类导入错误:类型“<组件名称>”中缺少属性“原型”,但类型“typeof <组件名称>”中需要属性“原型”。TS(2741)

尝试将一个组件导入到第二个组件时,我收到以下错误。

“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)

这是错误和沙箱的屏幕截图。

打字稿沙箱

在此输入图像描述

在此输入图像描述

typescript

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

express ×2

node.js ×2

graphql ×1

graphql-js ×1

typescript ×1