Async-graphql: Is there support for named queries?

Created on 16 Dec 2020  路  4Comments  路  Source: async-graphql/async-graphql

I think I'm probably missing things. But I cannot get them to work.
I have a named query:

    const FUND_BY_ID_ALL_ATTRIBUTES_QUERY: &str = r#"{
        query fundById($id: Int!) {
            fund(id: $id) {
                id,
                fundName,
                fundGoal,
            }
        }
    }"#;

And then a test:

...
let result = warp::test::request()
            .method("POST")
            .body(
                json!({
                    "query": FUND_BY_ID_ALL_ATTRIBUTES_QUERY,
                    "variables": {
                        "id": fund.id,
                    }
                })
                .to_string(),
            )
            .reply(&graphql_filter)
            .await;
...

And I cannot make it work.
If force the query as:

    const FUND_BY_ID_ALL_ATTRIBUTES_QUERY: &str = r#"{
        fund(id: 42) {
            id,
            fundName,
            fundGoal,
            votingPowerInfo,
            votingPowerThreshold,
            rewardsInfo,
            fundStartTime,
            fundEndTime,
            nextFundStartTime,
            chainVotePlans {
                id,
                chainVoteplanId,
                chainVoteStartTime,
                chainVoteEndTime,
                chainCommitteeEndTime,
                chainVoteplanPayload,
                chainVoteEncryptionKey,
                fundId
            },
        }
    }"#;

works like a charm.

This is the weir panic:

query had errors: [{"message":" --> 2:24\n  |\n2 |         query fundById($id: Int!) {鈵奬n  |                        ^---\n  |\n  = expected name","locations":[{"line":2,"column":24}]}]

question

All 4 comments

You have an extra brace, and the following is a valid GraphQL query.

query fundById($id: Int!) {
    fund(id: $id) {
      id,
      fundName,
      fundGoal,
    },
}

@sunli829, sorry, the brace was a typo from reducing the example. Since the original query has more fields.

Named query is supported. There is only one possibility for this error. The query statement does not conform to the GraphQL specification.

I'll check it deeper. I may be missing something for sure. Thanks for the quick replay @sunli829 !! 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GQAdonis picture GQAdonis  路  3Comments

AurelienFT picture AurelienFT  路  5Comments

Weasy666 picture Weasy666  路  4Comments

leebenson picture leebenson  路  4Comments

D1plo1d picture D1plo1d  路  4Comments