This is a demo project built using SwiftUI and follows the Model-View-ViewModel (MVVM) architectural pattern. It is designed to demonstrate fetching and displaying data from the "Rick and Morty" TV series using GraphQL. The project showcases the integration of modern development practices and tools in an iOS application.
- SwiftUI Framework: Utilizes SwiftUI for all UI components.
- MVVM Architecture: Adheres to the MVVM architectural pattern to ensure code modularity and separation of concerns.
- GraphQL Integration: Employs GraphQL for efficient data fetching specific to the needs of the application, reducing over-fetching and under-fetching issues.
- Apollo iOS Client: Incorporates the Apollo iOS Client for GraphQL integration, providing strong type usage and network management.
- iOS: Built targeting iOS 17.0 or later.
- Xcode: Compatible with Xcode 15.3 or newer.
Start by cloning the repository to your local machine. To clone the project, open a terminal and run:
git clone https://github.com/your-username/RickAndMortyGraphQL.git
cd RickAndMortyGraphQL
This project uses the Apollo iOS Client, which is integrated via Swift Package Manager (SPM). Dependencies should be automatically resolved when you open the project in Xcode. If needed, you can manually fetch and update the packages in Xcode by navigating to:
File -> Swift Packages -> Update to Latest Package Versions
Open the project in Xcode by double-clicking the .xcodeproj
file in the project directory. Select a target device or simulator and press Run
to build and run the project.
If building fails initially, it is likely due to the apolla CLI tool not being installed on your machine. It should ship with the respository, but if it's missing you can install it by right clicking on the RickAndMortyGraphQL target in the editor.
For information regarding this, please refer to the Apollo Documentation
GraphQL code generation is configured using the apollo-ios-cli
. The configuration file apollo-codegen-config.json
specifies how the Apollo tooling should generate Swift code based on GraphQL schemas and operations.
A custom run script in the Xcode build phases is set up to call a fetch and generate script.
This script fetches the GraphQL schema from this public URL: https://rickandmortyapi.com/graphql
To view or modify the script, refer to
RickAndMortyGraphQL/GraphQL/fetch-and-generate-schema.sh
The codegen properties are defined in
RickAndMortyGraphQL/apollo-codegen-config.json
This script is called via the 'Fetch Rick & Morty Scheme & Generate Code' run script.
To view or modify the run script:
- Navigate to the project settings in Xcode.
- Go to the 'Build Phases' tab.
- Expand the 'Fetch Rick & Morty Scheme & Generate Code' section to view the script details.