Coder Social home page Coder Social logo

parables / graphql-codegen-flutter-freezed Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 4.77 MB

This is the latest rewrite of the flutter-freezed plugin for dotmansia/graphql-codegen published as a stand-alone package.

License: MIT License

TypeScript 99.35% JavaScript 0.31% Shell 0.35%
flutter dart

graphql-codegen-flutter-freezed's Introduction

graphql-codegen-flutter-freezed

This is a stand-alone package based on the flutter-freezed plugin to generate Freezed from your GraphQL schema.

Dart is awesome, but defining a "model" can be tedious. We may have to:

  • define a constructor + the properties
  • override toString, operator ==, hashCode
  • implement a copyWith method to clone the object
  • handling de/serialization

On top of that, Dart is also missing features such as union types and pattern-matching.

Implementing all of this can take hundreds of lines, which are error-prone and the readability of your model significantly.

Freezed tries to fix that by implementing most of this for you, allowing you to focus on the definition of your model. https://pub.dev/packages/freezed

Creating these models by hand becomes even more complex when you are working with a GraphQL server that can handle nested mutations.

See this GraphQL Playground and ask yourself, how would I create a model to handle the data returned by this nested mutation below?

Please change the address in the playground to use https instead of http

# Write your query or mutation here
mutation createProgramme{
  createProgramme(input: {
    title: "GraphQL + Flutter",
    programmeCode: "graphql-dart-flutter-101",
    startLevel: 100,
    endLevel: 100,
    programmeOutlines: {
      create: {
        level: 100,
        course: {
          create:{
            title: "Flutter Freezed",
            courseCode: "CS-FF-101",
            books: {
              create:{
                title: "GraphQL is way awesome",
                author: "Parables Boltnoel"
              }
            }
          }
        }
      }
    }
  }){
    id
    title
    programmeCode
    programmeOutlines{
      level
      course{
        books{
          id
          title
          author
        }
      }
    }
  }
}

Fortunately enough, GraphQL is strongly typed, and so is Dart. Save yourself from implementing a model to match your strongly typed GraphQL operations, and let Freezed handle the work while you chill with this flutter-freezedplugin

Currently supports the following features

Features

Currently, the plugin supports the following features

  • Generate Freezed classes for ObjectTypes
  • Generate Freezed classes for InputTypes
  • Support for EnumsTypes
  • Support for custom ScalarTypes
  • Support freeze documentation of class & properties from GraphQL SDL description comments
  • Ignore/don't generate freezed classes for certain ObjectTypes
  • Support directives
  • Support deprecation annotation
  • [] Support for InterfaceTypes
  • Support for UnionTypes union/sealed classes
  • Merge InputTypes with ObjectType as union/sealed class union/sealed classes

TODO

  • Support Queries, Mutations, and Subscription: make it way easier to use GraphQL in flutter without going through any complex process. Inspired by KitQL

Installation

npm install -g graphql-codegen-flutter-freezed

Usage

In your Flutter project root, create a codegen.yml file.

This file is allows you to configure the generator.

overwrite: true
schema: './lib/data/graphql/schema.graphql'
generates:
  lib/data/models/app_models.dart:
    plugins:
      - typescript
      - flutter-freezed

Then simply run

Config API Docs

FAQ

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

yarn test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Enjoy ๐Ÿป

graphql-codegen-flutter-freezed's People

Contributors

parables avatar parables-amalitech avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.