I have a user.gql - file with some queries, mutations, inputs etc.
I get content of user.gql, using gql()
, then filter an document.definition to find needed a query. After filter
document.definitions
.filter(item => item.kind === 'OperationDefinition')
.filter(item => item.operation === 'query')
, one request object remains. smth like
{
kind: "OperationDefinition",
name: {kind: 'Name', value: 'authenticate'},
operation: "query",
selectionSet: {...}
variableDefinitions: [
...
]
}
How to convert it back to string? In the file this code is written like this
query authenticate($login: String!, $password: Password!) {
user(login: $login, password: $password) {
token,
name,
additional
}
}