Hello there, fellow Flutter and GraphQL explorers!
This repository contains the source code for the tutorial REST in Peace: Star Wars Meets GraphQL + Flutter! published on Medium. It demonstrates how to integrate GraphQL with Flutter while building a fun and informative Star Wars app!
Tired of over-fetching or under-fetching data with REST APIs? Say hello to GraphQL, the cool kid on the block that fetches only the data you need in a single request. This project is a Star Wars-themed Flutter app showcasing how GraphQL makes API consumption smarter and more efficient.
Dive into the code to see how GraphQL queries, mutations, and schema play nicely with Flutter.
This is the accompanying code for my article where we break down GraphQL basics, advantages over REST, and Flutter integration step by step.
- GraphQL Queries and Mutations: Fetch only what you need or send data efficiently.
- Star Wars API Integration: Explore the galaxy through the Star Wars API (SWAPI).
- Beginner-Friendly: Step-by-step implementation with easy-to-follow examples.
- Scalable Codebase: Designed with clean architecture principles in mind.
-
Clone the repository:
git clone https://github.com/tech-ramakant/graphql_demo_app.git
-
Navigate to the project directory:
cd graphql_demo_app
-
Install the dependencies:
flutter pub get
-
Run the app:
flutter run
Explore the code in the lib/ folder to see how GraphQL queries and mutations are implemented. Here's a small taste:
Example Query:
const String fetchStarships = r'''
query {
allStarships {
starships {
name
model
}
}
}
''';
final result = await client.query(QueryOptions(document: gql(fetchStarships)));
final starships = result.data?['allStarships']['starships'];
Example Mutation:
const String addReview = r'''
mutation($episode: Episode!, $review: ReviewInput!) {
createReview(episode: $episode, review: $review) {
stars
commentary
}
}
''';
final result = await client.mutate(MutationOptions(
document: gql(addReview),
variables: {
'episode': 'NEWHOPE',
'review': {'stars': 5, 'commentary': 'This app is out of this world!'}
},
));
Feel free to open issues or make pull requests to improve this project. Contributions are always welcome!
Fork the repo
- Create your branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For any inquiries, feel free to reach out to me via:
- Email: [email protected]
- Medium: @tech.ramakant
- LinkedIn: @tech-ramakant
- YouTube: @Tech.Ramakant