Docs
Launch GraphOS Studio

Mocking graph functionality to unblock client development

Enable teams to work in parallel without blocking each other

gatewayschema-designfederation

As your organization builds out its , you might discover that your client teams are often waiting on owners to make agreed-upon changes to their schemas. During this time, you can mock parts of your as you develop both your clients and , enabling teams to work in parallel without blocking each other.

First, agree on your schema

To mock parts of your effectively, both client and backend teams need to agree on the structure of those parts as part of a larger

and approval process. Alignment between these teams on schema additions/removals/changes can help make your schema more useful and expressive.

NOTE

We recommended that your backend and client teams align on your schema's structure ahead of time, even if you don't use schema mocking. Doing so enables you to create an expressive schema that accelerates all teams.

Creating a new schema

If you're creating an entirely new and corresponding schema, it's important first to familiarize yourself with schema best practices, such as those described in

,
Principled GraphQL
, and the
Enterprise Guide
.

For new schemas, we recommend using

to mock your new schema in its entirety. This provides your client teams with a local (or hosted) instance of the schema to against and begin mocking UI components with the mocked data.

To use this sample, you need to

. For details on the benefits of publishing to ,
see below
.

To get started with the sample, run the following:

git clone https://github.com/setchy/apollo-server-4-mocked-federation
cd apollo-server-4-mocked-federation
npm install
cp .env.template .env

Then, edit the .env file with the appropriate values from and run the following to start the server:

npm run dev

The sample uses the @graphql-tools/mock package to power the mocks. You can customize the sample's behavior by following the instructions in the

.

This gateway can then be used either locally (such as for local client development) or as a hosted gateway internally to be used by client developers.

The data is mocked, however it doesn't require any work from server teams to support and will match the schema as it exists within . As we're using GraphOS Studio for the schema, schema changes will automatically be pulled ensuring client developers are working on the latest version.

Modifying an existing schema

The process for making changes to an existing schema is similar to that for creating a new one, especially in terms of planning. As you add new features, it's important reach a design consensus early, especially for features that require extensive backend work (for example, machine learning).

To mock proposed changes (such as adding a new type/), we recommend using

. This sample requires a preexisting API to be running. It works by allowing for a "patched" or modified version of your to run locally with mocked data, while using the remote API for all other data.

You'll need to

to use this sample. For details on the benefits of publishing to ,
see below
.

To get started, run:

mkdir mocked_gateway
export APOLLO_KEY=key_from_studio #replace with the actual key from GraphOS Studio
cd mocked_gateway
touch proposed.graphql
npx github:@apollosolutions/apollo-faker-demo --graphref <yourgraph>@<variant> --remote https://yourapi.com/graphql

Then, modify the proposed.graphql file with the proposed changes. There are configuration options available via the @graphql-tools/mock package, and you can set these options as documented in

.

Why use GraphOS for a mocked server?

Now that you have either a new schema or changes to an existing one, it's important to publish that schema to for the following reasons:

  • provides a centralized view of your schema, along with a
    mocked view of the schema
    .
  • By publishing to , the samples referenced above can automatically update on changes, allowing for a deployed version of the samples to be referenced by all developers.
  • For client teams using code generation tools (especially those in Apollo's client libraries) it's possible to use as a source of the schema, allowing for more straightforward development.

We recommend using a of your new/existing production ID. If considering mocking for schema changes, this also ensures proposed changes aren't breaking using

against production traffic.

Next
Home
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company