![](/img/trans.png)
[英]How to use detalization queries in apollo graphql reactjs?
[英]How to send an Apollo Request (graphql) with queries?
我有這樣的任務,所以用這些參數發送一個查詢
{operationName:getPostList,variables:{input:{type:post,locale:en,projectId:1}},query:query getPostList($input: PostSearchType) {\n posts(input: $input, paging: {limit: 12}) {\n items {\n id\n type\n locale\n shortDescription\n fullUrl\n thumbnail\n tags\n title\n publishedAt\n __typename\n }\n __typename\n }\n}\n"}
但是我不明白如何在 gql function (apollo-boost) 中指定這些參數這是我的要求
const GET_MOVIES = gql`
{
query getPostList($input: PostSearchType){
posts(
input:$input,
paging : {
limit:12
}
items{
id,
type,
locale,
shortDescription,
fullUrl,
thumbnail,
tags,
title,
publishedAt,
__typename
}
__typename
)
}
"operationName":"getPostList",
"variables":{
"input":{
"type":"post",
"locale":"en",
"projectId":1
}
}
}
`
請查看示例代碼。 您可以根據自己的要求進行調整。
/**
* Sample code to showcase how queries work in React Apollo client
*/
import React from "react";
import gql from "graphql-tag";
import { useQuery } from "@apollo/react-hooks";
const GET_MOVIES = gql`
query getPostList($input: PostSearchType) {
posts(input: $input) {
id
type
locale
shortDescription
fullUrl
thumbnail
tags
title
publishedAt
__typename
}
}
`;
const ApolloReactExample = () => {
const { loading, data, error } = useQuery(GET_MOVIES, {
variables: { input: "YOUR_INPUT" },
});
return <div></div>;
};
export default ApolloReactExample;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.