Connecting to the GraphQL resolver

How to connect resolver in GraphQL

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:

  1. Create a file in src/app/query folder. Call it <FunctionalityPartName>.query.js.

  2. In there create a class called <FunctionalityPartName>Query.

  3. Implement query retrieval functionality. Do not forget to add export to the src/query/index.js file.

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