【发布时间】:2020-10-07 10:58:17
【问题描述】:
我尝试从 react 应用调用简单的 graphQl 突变。是变异描述:
createOrganization(
organization: OrganizationInput!
): Organization
type OrganizationInput {
name: String!
type: String
billingAddress: AddressInput
shippingAddress: AddressInput
}
我尝试称它为:
const CREATE_ORGANIZATION = gql`
mutation createOrganization($organization: OrganizationInput!) {
_id
}
`;
const [mutation] = useMutation(CREATE_ORGANIZATION);
...
mutation({
variables: { name: '' },
});
不幸的是,graphQl 没有提供任何可读的日志,我有:
Unhandled Rejection (Error): Network error: Response not successful: Received status code 400
new ApolloError
src/errors/ApolloError.ts:46
43 | // Constructs an instance of ApolloError given a GraphQLError
44 | // or a network error. Note that one of these has to be a valid
45 | // value or the constructed error will be meaningless.
> 46 | constructor({
| ^ 47 | graphQLErrors,
48 | networkError,
49 | errorMessage,
在网络中,我看到调用了突变,但我不知道当您使用 graphQl 时出现什么问题以及如何处理问题最重要。
附言它正在起作用 - 从 playgraund 调用它不是问题。
【问题讨论】:
-
让它在操场上工作使用“查询变量”(只有一个“组织”参数)-graphql.org/learn/queries/#variables ...然后在代码中重新创建
-
更改为mutation({ variables: { organization: { name: '' } }, });它仍然不起作用。在操场上没问题
-
语法仍然不好
-
我不明白...我看到很多样本,而且到处都是相同的简单方法。
-
只是硬编码误导......遵循这个文档和这种传递变量的方式
标签: reactjs graphql apollo-client