如何发送一个阿波罗请求(graphql)与查询?



我有这样的任务,所以发送一个查询与这些参数

{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      idn    typen   localen  shortDescriptionn fullUrln   thumbnailn   tagsn      titlen      publishedAtn      __typenamen    }n    __typenamen  }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;

最新更新