npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-codegen-flutter-freezed

v0.6.0

Published

A stand-alone package to generate Freezed models from GraphQL schema based on the flutter-freezed plugin for GraphQL Code Generator

Downloads

16

Readme

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

  • [x] Generate Freezed classes for ObjectTypes
  • [x] Generate Freezed classes for InputTypes
  • [x] Support for EnumsTypes
  • [x] Support for custom ScalarTypes
  • [x] Support freeze documentation of class & properties from GraphQL SDL description comments
  • [x] Ignore/don't generate freezed classes for certain ObjectTypes
  • [x] Support directives
  • [x] Support deprecation annotation
  • [] Support for InterfaceTypes
  • [x] Support for UnionTypes union/sealed classes
  • [x] 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 🍻