GraphQL vs EdgeDB

Despite being fundamentally different technologies, EdgeDB and GraphQL solve some of the same problems. GraphQL is a specification for implementing typesafe APIs, consisting of a data modeling language, a query language, and a set of associated tools. EdgeDB is a database, coupled with an associated data modeling language, a query language (EdgeQL), and set of associated tools.

Indeed GraphQL was a source of inspiration for the design of EdgeDB, specifically:

  • its succinct, declarative, object-oriented modeling language
  • its composable, syntax-rich query language
  • its intuitive approach to field selection and deep fetching

So below we compare GraphQL and EdgeDB side-by-side. If you're familiar with GraphQL, this should be an effective way to map syntax and concepts you're already familiar with from GraphQL onto EdgeDB. Moreover, the examples below will highlight scenarios where GraphQL falls short relative to a fully-fledged query language like EdgeQL.

Modeling

Both EdgeDB and GraphQL provide a schema definition language (SDL) for defining your schema. In the case of GraphQL it's your API schema; in the case of EdgeDB it's your application's data model. Let's see how these two SDLs stack up side-by-side.

Scalar types
Object types
Abstract types
Relations
Polymorphic types
Unions
Enums and Arrays
Custom scalars
Copy
# No native support for
# temporal or JSON fields

String
Boolean
Int
Float
ID
Copy
str
bool
int{16|32|64}
float{32|64}
uuid
bigint
decimal
sequence
datetime
duration
cal::local_datetime
cal::local_date
cal::local_time
json

By virtue of being a database instead of an API definition language, EdgeDB's SDL is far broader in scope than GraphQL, to include concepts like constraints, default values, computed properties/links, indexes, stored procedures, link properties, and much more. Check out the Data Modeling showcase for a more complete picture of EdgeDB's data modeling capabilities.

Query language

GraphQL and EdgeDB both feature an associated query language. To facilitate side-by-side comparison, we'll be considering a hypothetical GraphQL API that supports querying and mutation of your entire database.

In fact, this isn't just a hypothetical; EdgeDB instances can process EdgeQL queries! With the flip of a switch, you can query and mutate data in EdgeDB via GraphQL. For details, check out the GraphQL showcase page and documentation.

All queries in the following sections assume the following schema:

Copy
abstract type Person {
  required name: str {
    constraint exclusive;
  };
}

type Villain extending Person {
  nemesis: Hero;
}

type Hero extending Person {
  secret_identity: str;
  number_of_movies: int64;
  multi link villains := .<nemesis[IS Villain];
}

Querying

Simple query
Nested query
Basic filter
Nested filters
Advanced filtering
Pagination
Polymorphic query
Variables
Copy
query getHeroes {
  Hero {
    id
    name
    secret_identity
  }
}
Copy
select Hero {
  id,
  name,
  secret_identity
}

Mutation

Insert
Update
Delete
Insert multiple
Nested insert
Nested connect
Disconnect
Mutation + fetch
Copy
mutation {
  insert_Hero(data: {
    name: "The Falcon",
    secret_identity: "Sam Wilson"
  }) { id }
}
Copy
insert Hero {
  name := 'The Falcon',
  secret_identity := 'Sam Wilson'
};

The examples above draw comparisons between GraphQL and EdgeDB where possible. However, due to the fundamentally different nature of the technologies, there is a wide swath of EdgeDB features that are out of scope for an API specification language like GraphQL: computed properties, subqueries, with clauses, type casting, and a large set of built-in operators and utility functions. For a more comprehensive overview of EdgeDB features and syntax check out the EdgeQL showcase.