GraphQL is an open-source query and data manipulation language for APIs created by Facebook back in 2015. Although it is defined by the community as a probable replacement for REST, depending on each API architecture and requirements, some projects might be suitable for GraphQL API while others might be suitable for REST API. But due to its popularity for past years some major companies have already migrated their APIs to GraphQL APIs while some have opted for hybrid approach of using both REST and GraphQL at the same time.

Image by GraphQL

When comes to creating a GraphQL API many tools can be used to manage the creation of APIs. Some of the major and popular tools that are currently available to create GraphQL APIs are

  • GraphQL (graphql/graphql-js )
  • Apollo (apollographql/apollo-server )
  • Express graphQL (graphql/express-graphql )
  • Prisma ( https://www.prisma.io/)
  • AWS AppSync

Other than these there are many more tools currently as well as being developed as I write this article. All these tools have their own advantages as well as disadvantages among themselves. This article is not going to be about these tools comparison so let’s continue our GraphQL creation discussion.

When creating a GraphQL API the main component we need to do is define the GraphQL schema. There are two common ways we can do this.

  • Schema-first development
  • Code-first development

Schema First Development

In schema first development we first define the schema and then implement the code matching the definitions on the defined schema. To define the schema, we will use Schema Definition Language, which is a query definition language the GraphQL team introduced. Below is an example of how we can define a schema using the Schema-first development.

#mongoose #graphql #typescript #mongodb #api

GraphQL — Code First(Resolver-First) using TypeGraphQL and Typegoose
2.15 GEEK