Reactjs 从react应用程序调用graphQl时出错
我尝试从react应用程序调用简单的graphQl突变。这是一个描述:Reactjs 从react应用程序调用graphQl时出错,reactjs,graphql,apollo-client,Reactjs,Graphql,Apollo Client,我尝试从react应用程序调用简单的graphQl突变。这是一个描述: createOrganization( organization: OrganizationInput! ): Organization type OrganizationInput { name: String! type: String billingAddress: AddressInput shippingAddress: AddressInput } 我试图称之为: const CREATE_ORGANIZAT
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时最重要的是如何处理问题
p、 从playgraund调用它并没有问题。我发现了我的错误。这是在gql中。正确的版本是:
const CREATE_ORGANIZATION = gql`
mutation($organization: OrganizationInput!) {
createOrganization(organization: $organization) {
_id
}
}
`;
使用“查询变量”(仅一个“组织”参数)使其在操场上工作。。。然后在codechanged中重新创建以进行变异({variables:{organization:{name:''},});但它仍然不起作用。游乐场没什么问题还是很糟糕我不明白。。。我看到很多样本,到处都是相同的简单方法。只是因为硬编码错误。。。按照此文档和此方式传递变量