DEV Community

Cover image for Querying All Appwrite Developers - GraphQL Has Arrived
Jake Barnby for Appwrite

Posted on

Querying All Appwrite Developers - GraphQL Has Arrived

Hot on the heels of two huge releases comes Appwrite 1.2, bringing with it a brand new, highly anticipated service: GraphQL.

Our vision for Appwrite is always to meet developers where they are. Build relying on your knowledge, stack of choice, or preferred APIs.

Today, we take another step in following this vision. We’re happy to introduce an experimental GraphQL API. A new way to integrate with Appwrite and use all the services you already know and love.

In addition to a new API comes a GraphQL explorer, upgraded SDKs, and improvements to the documentation.

GraphQL API

GraphQL is a powerful technology that allows developers to easily and efficiently access data from an API. It provides a flexible and intuitive query language that makes it easy to retrieve exactly the data that an application needs. This eliminates the need for multiple round trips to the server and can reduce the amount of data that needs to be transferred, resulting in faster and more efficient applications.

The Appwrite GraphQL API offers full support for all of Appwrite’s services. This means you can manage your accounts, databases, storage, functions, and more, all via GraphQL queries and mutations.

The GraphQL API is exposed on the route /v1/graphql, all queries and mutations should be sent to this route as JSON, following the GraphQL HTTP request model:

{
  "query": "...",
  "operaiontName": "...",
  "variables": {},
}
Enter fullscreen mode Exit fullscreen mode

The query key should contain the query or mutation you want to execute. operationName and variables are optional fields. operationName should only be included if there are multiple operations in the query.

A mutation to create an account could like this:

mutation {
  accountCreate(
    userId: "unique()"
    email: "team@appwrite.io"
    password: "Team.Appwrite.IO"
  ) {
    _id
    _createdAt
    status
    email
  }
Enter fullscreen mode Exit fullscreen mode

To use variables, and allow re-using a query, the mutation could look like this:

mutation AccountCreate($userId: String!, $email: String!, $password: String!) {
  accountCreate(
    userId: $userId
    email: $email
    password: $password
  ) {
    _id
    _createdAt
    status
    email
  }
Enter fullscreen mode Exit fullscreen mode

With this mutation, the variables parameter also needs to be passed in the request, to fill in the values for userId, email and password:

{
  "userId": "unique()",
  "email": "team@appwrite.io",
  "password": "Team.Appwrite.IO"
}
Enter fullscreen mode Exit fullscreen mode

The mutation is now able to be used across multiple requests, all that would need to be changed are the values of the variables.

GraphQL Explorer

Appwrite GraphQL Explorer is a powerful tool for working with the new GraphQL API. Based on the Altair GraphQL client, it has a user-friendly interface that makes it easy to explore the GraphQL API, even for those new to the technology. It supports all the features of GraphQL, including query variables, fragments, and custom headers, which makes it a very versatile tool.

GraphQL Explorer Screenshot

You can find the instructions to run the GraphQL explorer in this Gist.

Some extra features make it even easier and more enjoyable to use:

  • Searchable documentation
  • One-click query generation from documentation
  • Intelligent auto-complete and error highlighting for queries
  • Support for multiple tabs and environments

SDK Updates

The Appwrite SDKs have all been updated to support the GraphQL API by including a new service of their own. This can be used to interact with the API in the same way as other SDK services:

import { Client, GraphQL } from "appwrite";

const client = new Client()
   .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your Appwrite Endpoint
   .setProject('[PROJECT_ID]');             // Your project ID

const graphql = new GraphQL(client);

const mutation = graphql.mutation({
   query: `mutation {
    accountCreate(
        userId: "unique()",
        email: "team@appwrite.io,
        password: "Team.Appwrite.IO"
    ) {
        _id
        email
    }
   }`
});

mutation.then(response => {
   console.log(response);
}).catch(error => {
   console.log(error);
});
Enter fullscreen mode Exit fullscreen mode

This makes it possible to take advantage of GraphQL regardless of your preferred language or application platform.

Appwrite is agnostic when it comes to client support; this means any other GraphQL client can be freely used for those comfortable with a different product.

Documentation

To keep Appwrite as easy to use as possible as new APIs are added - the documentation underwent an upgrade. There are now dedicated quick-start guides for REST, GraphQL and Realtime, making it easier to get started with any of the available APIs.

Documentation

To complement this expansion, there are now examples of REST requests and GraphQL queries for all services, so it is easy to see how to interact with Appwrite even if communicating directly over HTTP instead of via one of the many SDKs.

And More

Appwrite 1.2 includes other changes. Check out the changelog here for the full list of new features, bugs fixed and other changes.

Try It Now

We are super excited about releasing the GraphQL API, GraphQL Explorer, and SDK support. This update provides another powerful and intuitive way to access and manipulate Appwrite, and we hope it will greatly improve the developer experience. We encourage all developers to upgrade to this new version and take advantage of the new features. Thank you for your continued support, and we look forward to any feedback.

Learn more

You can use the following resources to learn more and get help:

Top comments (7)

Collapse
 
imolorhe profile image
Sir Muel I πŸ‡³πŸ‡¬

Hi there! Love to see that AppWrite is using Altair! ❀️ I was wondering if you could shed some light on why you chose to create a fork of Altair GraphQL Client, instead of pushing your changes upstream? I'm assuming the changes made are purely customisation related?

Collapse
 
jakebarnby profile image
Jake Barnby

Hey there! Yep, that's the case; the changes are only cosmetic and beyond what we were able to with custom themes πŸ˜„

Collapse
 
imolorhe profile image
Sir Muel I πŸ‡³πŸ‡¬

Happy to hear what else is missing and how it can be directly available through Altair itself

Collapse
 
arafat4693 profile image
Arafat • Edited

I would've use this baas, but unfortunately It can't be deployed for freeπŸ˜“.

Collapse
 
gewenyu99 profile image
Vincent Ge

Oracle cloud has a free tier machine with 2 GB of memory. This is enough for Appwrite :)

So yes, this can be hosted for free. If you don't like Oracle cloud, you can also wait for Appwrite cloud ;)

Collapse
 
mc-stephen profile image
Stephen Michael

it is free bruv and open-source, so what are you talking about or am i missing somthing here ?

Collapse
 
bigfish258 profile image
hutu zhu

nice