Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Graphql创建2个带有1个变异的条目_Javascript_Database_Graphql_Apollo_Postgraphile - Fatal编程技术网

Javascript Graphql创建2个带有1个变异的条目

Javascript Graphql创建2个带有1个变异的条目,javascript,database,graphql,apollo,postgraphile,Javascript,Database,Graphql,Apollo,Postgraphile,我以前从未遇到过这种情况,但只要一个突变就会创建两个条目: scheme.json: { "name": "createAdminConfigCategory", "description": "Creates a single `AdminConfigCategory`.", "args": [ { "name": "input", "description": "The exclusive i

我以前从未遇到过这种情况,但只要一个突变就会创建两个条目:

scheme.json:

    {
      "name": "createAdminConfigCategory",
      "description": "Creates a single `AdminConfigCategory`.",
      "args": [
        {
          "name": "input",
          "description": "The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.",
          "type": {
            "kind": "NON_NULL",
            "name": null,
            "ofType": {
              "kind": "INPUT_OBJECT",
              "name": "CreateAdminConfigCategoryInput",
              "ofType": null
            }
          },
          "defaultValue": null
        }
      ],
      "type": {
        "kind": "OBJECT",
        "name": "CreateAdminConfigCategoryPayload",
        "ofType": null
      },
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "kind": "INPUT_OBJECT",
      "name": "CreateAdminConfigCategoryInput",
      "description": "All input for the create `AdminConfigCategory` mutation.",
      "fields": null,
      "inputFields": [
        {
          "name": "clientMutationId",
          "description": "An arbitrary string value with no semantic meaning. Will be included in the\npayload verbatim. May be used to track mutations by the client.",
          "type": {
            "kind": "SCALAR",
            "name": "String",
            "ofType": null
          },
          "defaultValue": null
        },
        {
          "name": "adminConfigCategory",
          "description": "The `AdminConfigCategory` to be created by this mutation.",
          "type": {
            "kind": "NON_NULL",
            "name": null,
            "ofType": {
              "kind": "INPUT_OBJECT",
              "name": "AdminConfigCategoryInput",
              "ofType": null
            }
          },
          "defaultValue": null
        }
      ],
      "interfaces": null,
      "enumValues": null,
      "possibleTypes": null
    },
    {
      "kind": "OBJECT",
      "name": "CreateAdminConfigCategoryPayload",
      "description": "The output of our create `AdminConfigCategory` mutation.",
      "fields": [
        {
          "name": "clientMutationId",
          "description": "The exact same `clientMutationId` that was provided in the mutation input,\nunchanged and unused. May be used by a client to track mutations.",
          "args": [],
          "type": {
            "kind": "SCALAR",
            "name": "String",
            "ofType": null
          },
          "isDeprecated": false,
          "deprecationReason": null
        },
        {
          "name": "adminConfigCategory",
          "description": "The `AdminConfigCategory` that was created by this mutation.",
          "args": [],
          "type": {
            "kind": "OBJECT",
            "name": "AdminConfigCategory",
            "ofType": null
          },
          "isDeprecated": false,
          "deprecationReason": null
        },
        {
          "name": "query",
          "description": "Our root query field type. Allows us to run any query from our mutation payload.",
          "args": [],
          "type": {
            "kind": "OBJECT",
            "name": "Query",
            "ofType": null
          },
          "isDeprecated": false,
          "deprecationReason": null
        },
        {
          "name": "adminConfigCategoryEdge",
          "description": "An edge for our `AdminConfigCategory`. May be used by Relay 1.",
          "args": [
            {
              "name": "orderBy",
              "description": "The method to use when ordering `AdminConfigCategory`.",
              "type": {
                "kind": "LIST",
                "name": null,
                "ofType": {
                  "kind": "NON_NULL",
                  "name": null,
                  "ofType": {
                    "kind": "ENUM",
                    "name": "AdminConfigCategoriesOrderBy",
                    "ofType": null
                  }
                }
              },
              "defaultValue": "[PRIMARY_KEY_ASC]"
            }
          ],
          "type": {
            "kind": "OBJECT",
            "name": "AdminConfigCategoriesEdge",
            "ofType": null
          },
          "isDeprecated": false,
          "deprecationReason": null
        }
      ],
      "inputFields": null,
      "interfaces": [],
      "enumValues": null,
      "possibleTypes": null
    },
突变前数据:

{
  "data": {
    "allAdminConfigCategories": {
      "edges": []
    }
  }
}
{
  "data": {
    "createAdminConfigCategory": {
      "query": {
        "allAdminConfigCategories": {
          "edges": [
            {
              "node": {
                "id": 42
              }
            },
            {
              "node": {
                "id": 43
              }
            }
          ]
        }
      }
    }
  }
}
mutation something($name: String!) {
  createAdminConfigCategory(input: { adminConfigCategory: { name: $name } }) {
    query { # < Here's the issue
      allAdminConfigCategories {
        edges {
          node {
            id
          }
        }
      }
    }
  }
}
突变:

  mutation something($name: String!) {
    createAdminConfigCategory(input: { adminConfigCategory: { name: $name } }) {
      query {
        allAdminConfigCategories {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
变数

{ "name": "Jamie" }
突变后的数据:

{
  "data": {
    "allAdminConfigCategories": {
      "edges": []
    }
  }
}
{
  "data": {
    "createAdminConfigCategory": {
      "query": {
        "allAdminConfigCategories": {
          "edges": [
            {
              "node": {
                "id": 42
              }
            },
            {
              "node": {
                "id": 43
              }
            }
          ]
        }
      }
    }
  }
}
mutation something($name: String!) {
  createAdminConfigCategory(input: { adminConfigCategory: { name: $name } }) {
    query { # < Here's the issue
      allAdminConfigCategories {
        edges {
          node {
            id
          }
        }
      }
    }
  }
}
我在graphiql中执行这些查询:


这里没有创建两个条目;你的变异:

{
  "data": {
    "allAdminConfigCategories": {
      "edges": []
    }
  }
}
{
  "data": {
    "createAdminConfigCategory": {
      "query": {
        "allAdminConfigCategories": {
          "edges": [
            {
              "node": {
                "id": 42
              }
            },
            {
              "node": {
                "id": 43
              }
            }
          ]
        }
      }
    }
  }
}
mutation something($name: String!) {
  createAdminConfigCategory(input: { adminConfigCategory: { name: $name } }) {
    query { # < Here's the issue
      allAdminConfigCategories {
        edges {
          node {
            id
          }
        }
      }
    }
  }
}

在这里,我们只是直接从变异负载查询新创建的AdminConfigCategory。

没有看到解析器代码和其他相关后端代码,我们只能猜测根本原因。有趣的是,我将更新问题。我给我们写博文,所以所有的东西都是自动生成的。无论我们去哪里,更新quesiton都是我的scheme.json。否则,对于后端代码,什么都没有。就在GraphiqlThanky@Benjie内执行变异,我必须说,在变异内使用查询的唯一原因是我了解到这是您更新内部缓存的方式。我还有一个问题,这意味着缓存确实更新了,但视图没有更新。所以include query确实为我在数据库中创建了2个条目,删除query意味着只添加了1个条目,两个突变都会更新缓存,为什么包含查询会创建2个条目?要更新缓存,您还需要请求缓存需要更新的任何字段-目前您只获取id,因此没有其他属性需要更新。它不创建2个条目,只创建一个,但您将获取该条目以及以前创建的任何条目。