5a. generate graphql query with fragments using AST
jozef-slezak opened this issue · comments
Goal: modify graphql query string
Please refine the issue at the beginning of your work and contact @jozef-slezak if you have any technical questions.
Use case
User chooses list of entities (usually in the UI from the graphql introspection) then we need to generate multiple graphql queries with fragments.
API
arguments:
introspection
argument is graphql query introspection - you can download example instrospection result from browser devtools network when displaying https://test-introspection.herokuapp.com/console (explorer sidebar uses the introspection)io
argument is supposed to be used to write generate *.graphql file for each query (see chapter examples below) - please copy the CodeRW interface from src/package/react-lowcode and keep there only one write method.
generateGraphqlQueries(introspection, io: Writer): void
Algorithm requirements
- generate one graphql query for each introspection query root
- use only query root that is type of LIST
- use hardcode query limit 100
- generate graphql query fragments for graphql query type used in query root
- placa only scalar fields in the query fragment
- skip non scalar fields
- use graphql-js library for creating graphql query (without concatenating strings)
- write automated jest tests - assert/expect the *.graphql files (you need to mock the
io
)
Example
you can test query here: https://test-introspection.herokuapp.com/
# file src/rootLevel1s.graphql
query rootLevel1s {
rootLevel1s(limit: 100) {
...rootLevel1s_level1
}
}
fragment rootLevel1s_level1 on level1 {
id
bigint1
bool1
int1
date1
numberic1
title
timestamp2
timestamp1
time2
time1
seq
}
# file src/rootLevel2s.graphql
query rootLevel2s {
...rootLevel2s_level2
}
fragment rootLevel2s_level2 on level2 {
# scalar fields
}
@rastiq, we can simplify the API:
- not writing the file (just returning a string)
- you can return multiple queries