Movatterモバイル変換


[0]ホーム

URL:


Docs
Search Apollo content (Cmd+K or /)
Launch GraphOS Studio
HomeHomeSchema DesignSchema DesignConnectorsConnectorsGraphOS PlatformGraphOS PlatformRoutingRoutingResourcesResources
Apollo iOSApollo iOS

4. Running code generation


Now that we have both a schema and a query file, it's time to run code generation. To run code generation run the following command in Terminal from your project directory:

Bash
1./apollo-ios-cli generate

You should now see a newRocketReserverAPI folder in your project directory which contains the Swift package containing your generated source code.

Generated swift package folder

Add the generated SPM package to your project

With the code generated, next we need to add the generated SPM package to the project.

The default configuration for code generation creates a new Swift package for the schema module and operations. For more information on code generation such as differentmodule types you can generate ordifferent ways to run code generation see the documentation.

  1. In Xcode go toFile > Add Packages..., in the Add Package dialog selectAdd Local...

Add local package
  1. Select theRocketReserverAPI folder in the file dialog, then clickAdd Package

Add local package browser
  1. You should now see theRocketReserverAPI package included in your project

Package in project hierarchy
  1. Next, in Xcode select the project, then theRocketReserver target, and go toBuild Phases. Under theLink Binary With Libraries section click the+ sign

Link binary with libraries
  1. In the dialog that pops up, select theRocketReserverAPI library and clickAdd

Link binary with libraries dialog

Examine the generated code

In the Xcode project hierarchy, navigate toRocketReserver/Packages/RocketReseverAPI/Sources/Operations/Queries/LaunchListQuery.graphql.swift. It defines a root class,LaunchListQuery, with many nested structs below it. If you compare the structs to the JSON data returned in Sandbox Explorer, you see that the structure matches. These structs include properties only for the fields that your query requests.

Try commenting out theid property inLaunchList.graphql using a#, saving, then running code generation again. When the code generation completes, the innermostLaunch now only includes the built-in__typename and the requestedsite property.

Uncommentid inLaunchList.graphql and re-run code generation to restore the property.

Now that you've generated code and had a chance to see what's in there, it's time to get everything working end to end! Next, you willExecute your first query.


[8]ページ先頭

©2009-2025 Movatter.jp