These are examples of what we’ve seen in the wild. Feel free and try other options and share them with us!
Queries extend Swift model as static constants.We usually start the project by creating a
GraphQL
folder in the root folder of our project. Then, we generate the API.swift
file inside GraphQL
folder and add Scalars
, Query
, Mutation
and Subscription
folders if needed. To prevent any naming collisions we create custom queries in files that follow the pattern of <structure><action>
(e.g. HumanQuery.swift
or HumanSubscription.swift
).
This leaves us with a tree structure resembling
selection
variable, andquery
, mutation
and subscription
) should be called query
and mutation
and subscription
respectively.Queries extend SwiftUI views as static variables.Each SwiftUI component that relies on GraphQL data exports a query as a static value that can be used to obtain the data. Parent components then hoist selections from their children and create a query request to the server.