In the 2.11 release of Dreamfactory we added support for GraphQL, the open sourced query language written by Facebook. You can now harness the power of GraphQL inside of the API automation & integration structure of Dreamfactory. Both REST and GraphQL offer advantages and disadvantages depending on your use case. There are several articles and posts out there expanding on this, but let’s walk through how to incorporate this service in your Dreamfactory instance. GraphQL is available in all of our product levels: Open Source, Silver and Gold.
Create a new app.
- Start by creating a new app in the Admin Dashboard named whatever you like. For ease of use I recommending something very creative, such as GraphQL, or GraphiQL as we forked this 3rd party, in browser IDE to perform the query and mutation events.
- Make sure to mark the app active and assign a default role to it. Make sure the role has the correct privileges in order to interact with the service.
- There are other ways to do this, but by creating an app you have an easy way to acquire the API key you will need later.
Install the software.
- clear the cache:
php artisan cache:clear
Next, edit the graphiql package to add the Dreamfactory API key
- Locate the API key section under the following note:
//Defines a GraphQL fetcher using the fetch API
- You will see the headers object. This is where you need to put your key:
Head back to the Launchpad section and you should see a screen similar to this:
- This gives you a basic idea of some of the commands for GraphQL
- If you click on the <Docs tab it will give you access to the query and mutation root types. This documentation is all auto-generated from DreamFactory. As you click through you can see the type it returns, the arguments, etc.
Let’s create a query:
- How do you get the schema of a connected SQL Server database for instance?
- When you start to type in the name of the query, the text will start to auto correct, listing options that might match your query.
- If you type in the name of the query: getSqlServerTable and hit the play button, it will return the field listings automatically. You can then click on any of the fields and it will give you the type of the field.
Last Important Items:
Here are some links to further your learning on GraphQL and GraphiQL:
Please let us know your thoughts, and share any cool projects you are working on. Reach out on our social media pages or leave your thoughts below. Thanks for reading!
Get started with DreamFactory commercial edition by starting a
free on-premise trial.
Or, start a hosted trial now!