We’re glad to announce that Parse Server now has support for GraphQL. GraphQL is an open-source data query and manipulation language that helps developers build fast and stable apps. It uses types to ensure Apps only ask for what’s possible and provide clear and helpful errors.

Parse Server is now the easiest way to instantly create a GraphQL API.

The 3.5.0 release automatically generates the main queries and mutations to have a GraphQL API running on top of ParseServer, including: Auto Schema, Users Authentication, Files, Class Objects supporting all data types and CRUD operations for MongoDB and Postgres.

We’d like to thank Davi Macedo and Douglas Muraoka for making this happen.

The ParseGraphQLServer is an optional feature (like ParseLiveQuery) that can play together with ParseServer or solo. In addition to the traditional REST API, Parse Server automatically generates a GraphQL API based on your current application schema.

Getting Started with GraphQL

$ npm install -g parse-server mongodb-runner
$ mongodb-runner start
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground

After starting the server, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.

Note: Do NOT use --mountPlayground option in production.

Checking the API health

Run the following:

query Health {
  health
}

You should receive the following response:

{
  "data": {
    "health": true
  }
}

Creating your first object

Since your application does not have a schema yet, you can use the generic create mutation to create your first object. Run the following:

mutation CreateObject {
  objects {
    create(className: "GameScore" fields: { score: 1337 playerName: "Sean Plott" cheatMode: false }) {
      objectId
      createdAt
    }
  }
}

You should receive a response similar to this:

{
  "data": {
    "objects": {
      "create": {
        "objectId": "7jfBmbGgyF",
        "createdAt": "2019-06-20T23:50:50.825Z"
      }
    }
  }
}

Using automatically generated operations

Parse Server learned from the first object that you created and now you have the GameScore class in your schema. You can now start using the automatically generated operations!

Run the following to create a second object:

mutation CreateGameScore {
  objects {
    createGameScore(fields: { score: 2558 playerName: "Luke Skywalker" cheatMode: false }) {
      objectId
      createdAt
    }
  }
}

You should receive a response similar to this:

{
  "data": {
    "objects": {
      "createGameScore": {
        "objectId": "gySYolb2CL",
        "createdAt": "2019-06-20T23:56:37.114Z"
      }
    }
  }
}

You can also run a query to this new class:

query FindGameScore {
  objects {
    findGameScore {
      results {
        playerName
        score
      }
    }
  }
}

You should receive a response similar to this:

{
  "data": {
    "objects": {
      "findGameScore": {
        "results": [
          {
            "playerName": "Sean Plott",
            "score": 1337
          },
          {
            "playerName": "Luke Skywalker",
            "score": 2558
          }
        ]
      }
    }
  }
}

Learning more

Please look at the right side of your GraphQL Playground. You will see the DOCS and SCHEMA menus. They are automatically generated by analysing your application schema. Please refer to them to learn more about everything that you can do with your Parse GraphQL API.

Additionally, the GraphQL Learn Section is a very good source to start learning about the power of the GraphQL language.

What’s next for GraphQL

Our community continues working hard to add wonderful features to the GraphQL API, such as Cloud Code Functions, Subscriptions, and support to all other Parse Server routes. Additionally, Douglas Muraoka is currently working on adding a GraphQL API Console to the Parse Dashboard.

If you enjoy using GraphQL with Parse Server we would love to see your contributions to make it even better!

We’re looking forward to see what you build with Parse Server and GraphQl 🚀

Tom Fox,