planetarium / mimir

A backend service that provides 9c-related utility APIs.
https://nine-chronicles.dev/
GNU Affero General Public License v3.0
1 stars 5 forks source link

Failed to get query result when using graphql_request #184

Closed ipdae closed 2 months ago

ipdae commented 3 months ago

i'll try this ts script when get query result from mimir with graphql_request

import { gql, request } from "https://deno.land/x/graphql_request/mod.ts";

async function getSheets(): Promise<string> {
    const endPoint: string = "https://mimir.nine-chronicles.dev/graphql/";
    const query = gql`
        query {
            odinWb: sheet(planetName: ODIN, sheetName: "WorldBossListSheet") {
                csv
            }
            heimdallWb: sheet(planetName: HEIMDALL, sheetName: "WorldBossListSheet") {
                csv
            }
            odinArena: sheet(planetName: ODIN, sheetName: "ArenaSheet") {
                csv
            }
            heimdallArena: sheet(planetName: HEIMDALL, sheetName: "ArenaSheet") {
                csv
            }  
        }
        `;
    const data = await request(endPoint, query);
    return data.data.odinWb.csv;

it will return response 200 with errors. the expected result of the query data is contained in the error.

moreal commented 3 months ago

Hello @ipdae, it seems you're using Deno and I love Deno too 😉

The graphql_request deno package seems a fork of graphql-request.

I had that problem with the 9c-board project and it seems to have been fixed in graphql-request version 5 or 6. However, for the forked version, 4.1.0 is the latest, so I don't think it would have gotten this fix.

And Deno supports to import npm package. You can import npm graphql-request package like below:

import { gql, request } from "npm:graphql-request@7.1.0"

So I rewrite some parts and the below script was succeeded.

import { gql, request } from "npm:graphql-request@7.1.0";

async function getSheets(): Promise<string> {
    const endPoint: string = "https://mimir.nine-chronicles.dev/graphql/";
    const query = gql`
        query {
            odinWb: sheet(planetName: ODIN, sheetName: "WorldBossListSheet") {
                csv
            }
            heimdallWb: sheet(planetName: HEIMDALL, sheetName: "WorldBossListSheet") {
                csv
            }
            odinArena: sheet(planetName: ODIN, sheetName: "ArenaSheet") {
                csv
            }
            heimdallArena: sheet(planetName: HEIMDALL, sheetName: "ArenaSheet") {
                csv
            }  
        }
        `;
    const data = await request(endPoint, query);
    return data.odinWb.csv;
}

getSheets().then(console.log).catch(console.error);
$ deno run --allow-env=NODE_ENV --allow-net=mimir.nine-chronicles.dev /tmp/run.ts
id,boss_id,started_block_index,ended_block_index,fee,ticket_price,additional_ticket_price,max_purchase_count
1,900001,5045201,5095600,1,1,1,40
2,900001,5362001,5412400,1,1,1,40
3,900001,5599601,5650000,1,1,1,40
4,900001,5902001,5952400,1,1,1,40
5,900002,6002801,6053200,1,1,1,40
6,900002,6154001,6204400,1,1,1,40
7,900002,6305201,6355600,0,1,1,40
8,900001,6506801,6557200,1,1,1,40
9,900002,6658001,6708400,1,1,1,40
10,900001,6809201,6859600,1,1,1,40
11,900002,7010801,7061200,1,1,1,40
12,900001,7111601,7162000,1,1,1,40
13,900002,7262801,7313200,1,1,1,40
14,900001,7414001,7464400,1,1,1,40
15,900002,7615601,7666000,1,1,1,40
16,900001,7716401,7766800,1,1,1,40
17,900002,7867601,7918000,1,1,1,40
18,900001,8018801,8119600,1,1,1,40
19,900002,8220401,8341360,1,1,1,40
20,900001,8462321,8613520,1,1,1,40
21,900002,8764721,8915920,1,1,1,40
22,900001,9067121,9218320,1,1,1,40
23,900002,9369521,9520720,1,1,1,40
24,900001,9671921,9823120,1,1,1,40
25,900002,10025619,10176818,1,1,1,40
26,900001,10267216,10440016,1,1,1,40
27,900002,10440017,10612817,1,1,1,40
28,900001,10684001,10835200,1,1,1,40
29,900002,11131301,11282500,1,1,1,40
30,900001,11433701,11584900,1,1,1,40
31,900002,11736101,11887300,1,1,1,40
32,900001,12038501,12189700,1,1,1,40
33,900002,12340901,12492100,1,1,1,40
34,900001,12643301,12794500,1,1,1,40
moreal commented 2 months ago

@ipdae Can I assume as this issue is resolved?

ipdae commented 2 months ago

@moreal i'll test this within today.

ipdae commented 2 months ago

it works. thanks 😄