データをJSONとして投稿する必要がある既存のRESTAPIがあります。 URLパラメータは受け入れません。 ドキュメントを調べましたが、これについては話していないようです。 これはサポートされていますか?
これが私が達成しようとしていることの例です:
curl -X POST http://localhost:8000/rest-auth/login/ -d '{}'
前もって感謝します!
bodyKey/bodyBuilder
が私が探していたものだと思います。
私はこのようなことをしようとしてきました:
mutation login ($username: String!, $password: String!) {
login @rest(
method: "POST",
endpoint: "default",
path: "rest-auth/login/",
input: {username: $username, password: $password}
) {
results
}
}
しかし、私はこのエラーを受け取り続けます:
[GraphQL mutation using a REST call without a body]. No `input` was detected. Pass bodyKey, or bodyBuilder to the @rest() directive to resolve this.
私のRESTリンクは次のようになります。
export const restLink = new RestLink({
endpoints: {
default: process.env.REACT_APP_HOST_URL,
},
headers: {
"Content-Type": "application/json"
},
credentials: "same-origin",
})
私のクライアントは次のようになります。
const client = new ApolloClient({
link: ApolloLink.from([ stateLink, restLink ]),
cache: cache,
defaultOptions,
})
そうです、bodyKey / inputが必要です。
まず、ディレクティブに入力を渡しているので、おそらく次のことが必要です。
mutation login ($username: String!, $password: String!) {
login(input: {username: $username, password: $password}) @rest(
method: "POST",
endpoint: "default",
path: "rest-auth/login/",
) {
results
}
}
しかし、それはうまくいかないかもしれません。私たちは、あなたがしているように「入力」を動的に構築できないというバグがあると思います。 (私はそのバグを修正してもらいたいです)
試す:
input LoginInput { # you can omit this whole declaration with ApolloLink Rest
username: String!
password: String!
}
mutation login(input: LoginInput!) {
login(input: $input) @rest(
method: "POST",
endpoint: "default", # if you only have 1 endpoint, you can omit this too if you create your rest link the right way
path: "rest-auth/login/",
) {
results
}
}
この最後の例は、基本的に私のアプリが持っているものです。
@ fbartho-ありがとう! これは多くのことを明らかにしました。 そうです、私は誤ってディレクティブに入力を入れていました。
最も参考になるコメント
そうです、bodyKey / inputが必要です。
まず、ディレクティブに入力を渡しているので、おそらく次のことが必要です。
しかし、それはうまくいかないかもしれません。私たちは、あなたがしているように「入力」を動的に構築できないというバグがあると思います。 (私はそのバグを修正してもらいたいです)
試す:
この最後の例は、基本的に私のアプリが持っているものです。