You've probably used wunderctl already to initialize a new WunderGraph project. If not, please follow the first steps guide to get your started.
Assuming your WunderGraph project is set-up correctly, you should fine one important file in front of you:
You might want to take a shortcut and directly look into the code and explore the concepts yourself. If that's you, just open the file wundergraph.config.json, it should be straight forward.
WunderGraph is built around the concept that all configuration should be possible using code. This allows you to fully customize your WunderGraph applications to your needs as well as allowing you to store your configuration in a git repository.
The former gives you a lot of freedom, the latter allows you to integrate WunderGraph into your Continuous Deployment pipeline, allowing for a nice GitOps integration.
To configure a WunderGraph application, you have to follow three simple steps.
- introspect one or more APIs
- combine the APIs into an application
- call "configureWunderGraph" to generate the WunderGraph configuration (wundergraph.config.js) and the clients.
Let's explore the different options of introspecting APIs
In case you have an existing service which implements the GraphQL specification, use the following approach:
This code makes an introspection requests to the service and generates an API object from it.
This code assumes that the four services implement the GraphQL Federation specification. The WunderGraph sdk will introspect them with an introspection Query and combines them into a federated GraphQL API object.
WunderGraph also supports REST APIs, which get translated to GraphQL automatically. Here's one possible way of adding an OpenAPI based API to WunderGraph:
This code reads the OpenAPISpecification from the filesystem and translates it into an API object.
Now that you have one or more APIs introspected you're ready to combine them into an Application:
Simply add your api(s) to the application to combine their schemas into one single application schema.
You should now have a WunderGraph application object ready to use.
The final step is to turn this application into a WunderGraph configuration file.
wundergraph.config.json can be used by wunderctl to start a local dev environment.
First, provide your application(s) to the options object. Next, configure the code generators.
In this case, we're generating a typescript client for our application. Because some application frameworks restrict the directories from which you can import files, you're able to configure the output folder for the client templates.
Once you're happy with your configuration, you can start the sdk.
This will run the sdk in watch mode. Whenever you make a change, the wundergraph.config.json will be re-generated.
Lastly, you have to run a local WunderGraph dev environment using the wundergraph.config.json