DocumentationIntroduction

Introduction

GraphQL Tools is a set of npm packages(@graphql-tools/*) and an opinionated structure for how to build a GraphQL schema and resolvers in JavaScript, following the GraphQL-first development workflow.

Functions in the @graphql-tools/* packages are not only useful for building servers. They can also be used in the browser. For example, to mock a backend during development or testing.

Even though we recommend a specific way of building GraphQL servers, you can use these tools even if you don’t follow our structure; they work with any GraphQL-JS schema, and each tool can be useful on its own.

Using GraphQL with HTTP

If you want to bind your JavaScript GraphQL schema to an HTTP server, you can use GraphQL Yoga.

You can develop your JavaScript-based GraphQL API with GraphQL Tools and GraphQL Yoga together: One to write the schema and resolver code, and the other to connect it to a web server.

The GraphQL-First Philosophy

This package enables a specific workflow for developing a GraphQL server, where the GraphQL schema is the first thing you design, and acts as the contract between your frontend and backend. It’s not necessarily for everyone, but it can be a great way to get a server up and running with a very clear separation of concerns. These concerns are aligned with Facebook’s direction about the best way to use GraphQL, and our own findings after thinking about the best way to architect a JavaScript GraphQL API codebase.

  1. Use the GraphQL schema language. The official GraphQL documentation explains schema concepts using a concise and easy-to-read language. The getting started guide for GraphQL.js now uses the schema to introduce new developers to GraphQL. graphql-tools enables you to use this language alongside with all the features of GraphQL including resolvers, interfaces, custom scalars, and more so that you can have a seamless flow from design to mocking to implementation. For a more complete overview of the benefits, check out Nick Nance’s talk, Managing GraphQL Development at Scale.
  2. Separate business logic from the schema. As Dan Schafer covered in his talk, GraphQL at Facebook, it’s a good idea to treat GraphQL as a thin API and routing layer. This means that your actual business logic, permissions, and other concerns should not be part of your GraphQL schema. For large apps, we suggest splitting your GraphQL server code into 4 components: Schema, Resolvers, Models, and Connectors, which each handle a specific part of the work.
  3. Use standard libraries for auth and other special concerns. There’s no need to reinvent the login process in GraphQL. Every server framework already has a wealth of technologies for auth, file uploads, and more. It’s prudent to use those standard solutions even if your data is being served through a GraphQL endpoint, and it is okay to have non-GraphQL endpoints on your server when it’s the most practical solution.
Last updated on