Multiple arguments for a query using graphql and apollo

Viewed 57

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. 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.

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}`));
        }
1 Answers

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

e.g.

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

where T is the shape of your TimeFrame type, presumably something like {start: String!: end, String!}

Related