问题描述
{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 函数(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;