我一直在关注https://www.howtographql.com/上的 React-Apollo 和 Node.js GraphQL 教程,并且能够启动并运行演示。
我现在想做的是将我的查询结果作为数组返回。
我的 schema.graphql 文件如下所示:
type Query{
pullTickets (where: TicketWhereInput): [Ticket!]!
}
解析器看起来像:
const resolvers = {
Query: {
pullTickets: (root, args, context, info,) => {
return context.db.query.tickets({}, info)
}
}
}
到目前为止,我尝试过的是:
import React, { Component } from 'react';
import Query from "react-apollo/Query";
import gql from "graphql-tag";
const GET_TICKETS = gql`
query getTickets($startDate: DateTime!, $endDate: DateTime!) {
pullTickets (where: {
AND:[{DateCloseDate_gt: $startDate}, {DateCloseDate_lt: $endDate}]})
{
id
}
}
`;
export default function GetTickets ( startDate, endDate ) {
var temp = [];
<Query query={GET_TICKETS} variables={{ startDate, endDate }} >
{({ loading, error, data }) => {
if (loading) return 'Loading...';
if (error) return `Error!: ${error}`;
// This doesn't seem to do anything
temp = data.pullTickets
}}
</Query>
// temp is showing up as "undefined" in the console
console.log(temp);
return temp
}
我应该得到一张门票清单,但我没有定义。