简体   繁体   English

使用 graphql 和 apollo 的查询的多个参数

[英]Multiple arguments for a query using graphql and apollo

This may be a very stupid question, but I am kinda stuck.这可能是一个非常愚蠢的问题,但我有点卡住了。

When I want to get all the project queries based on a project id, everything works like a charm.当我想根据项目 ID 获取所有项目查询时,一切都像魅力一样。 What I want to do is to get only the project queries within a certain timeframe.我想要做的是在某个时间范围内只获取项目查询。

Where can I specify additional arguments for that?我在哪里可以为此指定其他参数?

I am using MongoDB, Apollo and Graphql, all in Typescript.我在 Typescript 中使用 MongoDB、Apollo 和 Graphql。

Thanks!谢谢!

Query询问

const GET_QUERY_DATA = gql`
    query getQueryData($projectId: String!) {
        projectQueries(id: $projectId) {
            number
            latency
            complexity
            loggedOn
            depth
            timestamp
            tokens
            success
        }
    }
`;

Resolver:解析器:

projectQueries: (parent: undefined, args: QueryByID): Promise<ProjectQuery[] | Error> => {
            const { id } = args;
            return QueryDB.find({ projectID: id })
                .then((queries: ProjectQuery[]): ProjectQuery[] => queries)
                .catch((err: Error): Error => new Error(`DB query failed: ${err}`));
        }

you're already passing a variable so it would sit next $projectId and by the looks of it, the timerange property would need adding to QueryByID您已经传递了一个变量,因此它将位于下一个$projectId并且看起来, timerange 属性需要添加到QueryByID

eg例如

query getQueryData($projectId: String!,$timeFrame:T) {

where T is the shape of your TimeFrame type, presumably something like {start: String!: end, String!}其中 T 是您的TimeFrame类型的形状,大概类似于{start: String!: end, String!}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM