I
I
Ivan Huk2020-06-27 16:25:40
React
Ivan Huk, 2020-06-27 16:25:40

How to pass parameter to graphql file?

I started to study graphql and ran into this problem:
How to properly import a graphql file into react.js and how to pass a variable to the imported file

code:

query GetAllProjects{
    getAllProjects{
        id,
        title,
        slug,
        content
    }
    getProjectInfo{
        id,
        title,
        slug,
        content
    }
}


I import like this:

import * as GetAllProjects from '../graphql/project.graphql';


and I want to call getProjectInfo , but I need to pass two parameters there

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
POVAL, 2022-01-16
@POVAL

Like this:

query GetAllProjects($param: TypeParam, $param2: TypeParam2){
    getAllProjects{
        id,
        title,
        slug,
        content
    }
    getProjectInfo(param: $param, param2: $param2){
        id,
        title,
        slug,
        content
    }
}

You can write requests in Apollo Studio (if you use it), and copy from there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question