Docs
Launch GraphOS Studio

Project configuration

Structuring a GraphQL application with the Apollo iOS SDK


1.0 can support complex applications composed of multiple modules and monolithic application targets.

The code generation engine and modularized structure of the Apollo iOS SDK provide flexible configuration options, enabling you to structure your project as you like.

This article covers the models generated by Apollo iOS, the modules that compose the Apollo iOS SDK, and how to structure these components in your project.

Generated models

Apollo iOS generates the following groups of files for you:

  • Operation models: Models for the queries, , , and defined in your files.
  • Schema types: Your 's shared types and metadata (e.g., objects, enums, input objects).
  • Test mocks: Test mock objects for your schema types, which you can use to create models in your tests.

Operation models

Apollo iOS generates operation models from the files where you define your GraphQL (i.e., queries, mutations, subscriptions, and fragments).

models are classes that represent your GraphQL operations, which you can then use to make GraphQL requests (via ApolloClient).

Each operation model includes a set of type-safe response model objects, representing that operation's result. When ApolloClient successfully executes a GraphQL request, it returns an instance of the corresponding response model for the executed operation.

To learn more about GraphQL operations, check out Defining operations.

Schema types

use a to define the shape of your available data. GraphQL operations (and your generated operation models) depend on a schema to know how to shape their operations to access a server's data.

Apollo iOS generates a collection of types that provide the properties and metadata about each type in your GraphQL schema (i.e., objects, interfaces, unions, enums, input objects, etc.). Your generated operation models reference these shared schema types to provide type information without duplicating code.

Test mocks

Apollo iOS enables you to generate test mock objects that you can use in your test targets. These mocks enable you to create operation models for your tests.

For more details, see Test Mocks.

Structuring your project

When including Apollo iOS in a new project, deciding how to structure your project is an essential first step. A large part of this step is determining where your generated GraphQL models fit.

You can include your GraphQL models in your main application target, spread them across many modules, or expose them as an independent module that multiple applications can use. Depending on the needs and constraints of your project, you'll configure the code generation engine and link to the Apollo iOS libraries differently.

There are three primary decisions you'll need to make about your project structure when using Apollo iOS:

  1. Will your project interact with Apollo in a single target or through multiple modules?
  2. Which schema moduleType should you use?
  3. Where should your generated operation models be located?

Over the next few pages, we will cover each of these questions and the possible choices for each.

Previous
Get Started
Next
1. Project Modularization
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company