Connecting to the GraphQL resolver
A step-by-step algorithm of creating a query
ScandiPWA is provided with functionality that allows writing GraphQL queries quickly and easily. You will learn to implement a simple query.
Imagine having a following GraphQL schema:
Create a file in
src/app/queryfolder. Call it<FunctionalityPartName>.query.js.In there create a class called
<FunctionalityPartName>Query.Implement query retrieval functionality. Do not forget to add export to the
src/query/index.jsfile.
Note:
ScandiPWA provides Field class as a helper to write GraphQL queries. It is strongly recommended to stick to it as to the only possible way of query implementation
4. Use the query!
Natural question should arise at this point: what does input contain?
Answer is pretty trivial. It is a simple JS object, which has exactly the same structure as defined in SendRmaMessageInput type in the schema. This case it should be the following:
Generally, there are two options how data can be fetched in ScandiPWA: through Service Worker (in most cases you want to use this option) or around it.
To use SW you need to create a dispatcher in src/app/store/<FunctionalityPartName> that inherits from QueryDispatcher, as follows:
To ignore SW functionality functions fetchQuery and fetchMutation can be used as in example below. Simple promise-based workflow.
Last updated