Backend teams are striving to build and deploy the APIs for front-end teams to deliver apps fast. They are driven by the frontend teams' desire to provide better performance and an enhanced developer experience.

In Why Backend Developers Should Fall in Love with GraphQL too, Anant Jhingran summarizes some of the concerns we hear in our conversations with the developers responsible for building and delivering these APIs:

  • Neither my team nor I have all the skills to build out GraphQL APIs.
  • GraphQL represents a new compromise vector. We locked down SQL injection, then REST, and now I have to worry about something else?
  • Current tools in GraphQL make mixing business logic and application logic easy, and that is an anti-pattern.
  • I have years of investment in REST endpoints - do I need to throw that away and start from scratch?

These concerns are generally valid, but as is often the case with any new technology, the reality is not as bad as it might seem. Plus, serving GraphQL is a dynamic software development landscape, with open source tools and companies like Apollo, Hasura, and StepZen beginning to address these concerns.

This brings me to a question we're frequently asked — how StepZen compares to Hasura or Apollo (Server).

Hasura vs. StepZen

Hasura is a web service that connects to your new or existing databases to quickly create a GraphQL API. It is a terrific product if your starting point is a database. Hasura offers quick conversion of database data into GraphQL via its intuitive web UI, hosting for the GraphQL endpoint, and a generous free tier.

In StepZen, instead of writing hundreds of lines of code or clicking through a UI, you can create a GraphQL API for your database using a few lines of code amd GraphQL directive @dbquery - right in the GraphQL schema.

type Article {
    id: ID!
    title: String!
    description: String
    }
    
type Query {
    articles(username:String!):[Article]
        @dbquery (
            type: "mysql"
            table: "articles"
            )
        }

Furthermore, we speak with many developers who have to deal with heterogeneous backends, not only databases — you have REST backends — both private and public SaaS REST APIs — and increasingly even GraphQL backends. StepZen makes it easy for these various backends to be combined:

type Author {
    name: String!
    }

type Article {
    id: ID!
    title: String!
    description: String
    authorID: ID!
    author: Author
        @materializer(
            query: "userByID"
            arguments: [{ name: "id" field: "authorID"}]
        )
}

type Query {
    articles(username:String!):[Article]
        @dbquery (
            type: "mysql"
            table: "articles"
        )
    authorByID(id: ID!): Author
        @rest(endpoint: "https://dev.to/api/users/$id")
    }

In StepZen, the code you write to create the API is approximately the code you need to write to run, manage and maintain that API. You can deliver an awesome, secure, and performant GraphQL API without you having to write more code. The API should scale, maintain a fixed IP address for your backends, and be automatically patched for the latest security flaws. StepZen’s cloud, with 99.99% availability, does all of that for you.

Apollo vs. StepZen

Apollo has been delivering GraphQL capabilities for a few years and has a mature collection of tools to smooth your journey to a GraphQL API. With Apollo, you write code to connect with your backends. So instead of being able to declaratively connect a database or API, you must write and maintain custom resolver code.

In this example from the Apollo docs, ​​you first create the code to create a GraphQL schema — clients can execute a query named books, and the Apollo server returns an array of zero or more Books.

const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`

  type Book {
    title: String
    author: String
  }

  type Query {
    books: [Book]
  }
`;

Then the code to define your data set.

const books = [
  {
    title: 'The Awakening',
    author: 'Kate Chopin',
  },
  {
    title: 'City of Glass',
    author: 'Paul Auster',
  },
];

Then you create a resolver to define the technique for fetching the types defined in the schema.

const resolvers = {
  Query: {
    books: () => books,
  },
};

Then create an instance of Apollo Server.

const server = new ApolloServer({ typeDefs, resolvers });

server.listen().then(({ url }) => {
  console.log(`🚀  Server ready at ${url}`);
});

In StepZen, your graph is constructed by adding just a few lines to your schema (SDL file), like this for REST, taking advantage of our custom GraphQL directive @rest to easily connect a REST backend.

type Article {
  id: ID!
  title: String!
  description: String
}
type Query {
  articles(username:String!):[Article]
  @rest(endpoint: "https://dev.to/api/articles?username=$username")
}

Real success in GraphQL implies that your GraphQL API must be scalably deployed, protected, be performant, and handle changes. While you can do all of that if you start with Apollo, you will have to learn new skills, import new libraries, and deploy more infrastructure to achieve it all.

With StepZen you build your GraphQL layer declaratively, just like you build databases declaratively, without writing application server code. The code you write to create the API is approximately the code you need to write to run, manage and maintain that API. Your GraphQL runs on StepZen, so you have no infrastructure to manage, and you get built-in performance, cost, and reliability optimizations.

Recap

Building out the APIs that someone else (or even you) uses is better done with GraphQL. GraphQL helps you deliver more intuitive APIs to your users. Stitching functionality together helps you effectively mix and match responses from backends. GraphQL fragments help with the abstraction and details continuum, and introspection along with self-documentation capabilities save you time.

The GraphQL ecosystem is maturing and adoption accelerating. Developers have choices - tools and libraries that solve different sets of problems or solve problems in different ways. We've just scrated the surface of the capabilities provided by a few in this post.

StepZen's vision is for developers to get an awesome, secure, and performant GraphQL API without you having to write and maintain more code and that the API should scale, maintain a fixed IP address for your backends, and be automatically patched for the latest security flaws. StepZen’s cloud, with 99.99% availability, does all of that for you, without you having to do anything.

To help you get started we provide pre-built SaaS APIs and introspection across your database and REST backends, let you build graphs by dropping in a few lines of declarative code, and then sit back and enjoy a highly performant GraphQL API. Check out StepZen docs and pre-built SaaS APIs in the GraphQL Studio. We're always keen to see what you're building and answer any questions on Discord!