All Projects → comigor → Artemis

comigor / Artemis

Licence: mit
Build dart types from GraphQL schemas and queries

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Artemis

Next Ecommerce
⚡️ Quantum Ecommerce. Made with Next.js | GraphQL | Apollo Server | Apollo Client | SSR
Stars: ✭ 186 (-41.32%)
Mutual labels:  graphql, apollo
Kit
ReactQL starter kit (use the CLI)
Stars: ✭ 232 (-26.81%)
Mutual labels:  graphql, apollo
React Native Fullstack Graphql
🚀 Starter projects for mobile applications based on React Native & GraphQL.
Stars: ✭ 208 (-34.38%)
Mutual labels:  graphql, apollo
Gatsby Woocommerce Themes
⚡ A Gatsby Theme for WooCommerce E-commerce site Gatsby WooCommerce WordPress
Stars: ✭ 306 (-3.47%)
Mutual labels:  graphql, apollo
Workers Graphql Server
🔥Lightning-fast, globally distributed Apollo GraphQL server, deployed at the edge using Cloudflare Workers
Stars: ✭ 255 (-19.56%)
Mutual labels:  graphql, apollo
Fullstack Boilerplate
Fullstack boilerplate using Typescript, React, GraphQL
Stars: ✭ 181 (-42.9%)
Mutual labels:  graphql, apollo
Canner
⚡️[NOT MAINTAINED] Content Management Framework creates custom CMS fast and easy. Support data sources such as Firebase/Firestore, GraphQL and Restful APIs.
Stars: ✭ 2,472 (+679.81%)
Mutual labels:  graphql, apollo
Ran
⚡ RAN! React . GraphQL . Next.js Toolkit ⚡ - SEO-Ready, Production-Ready, SSR, Hot-Reload, CSS-in-JS, Caching, CLI commands and more...
Stars: ✭ 2,128 (+571.29%)
Mutual labels:  graphql, apollo
Scalable React Boilerplate
⭐️ Scalable feature-first React micro-framework made for Udacity Alumni collaborative projects
Stars: ✭ 260 (-17.98%)
Mutual labels:  graphql, apollo
Graphql Deduplicator
A GraphQL response deduplicator. Removes duplicate entities from the GraphQL response.
Stars: ✭ 258 (-18.61%)
Mutual labels:  graphql, apollo
React Auth App Example
An app example with authentication using Create React App, React, React Router, Apollo, GraphQL, Redux and Redux Form.
Stars: ✭ 179 (-43.53%)
Mutual labels:  graphql, apollo
Babel Plugin Import Graphql
Enables import syntax for .graphql and .gql files
Stars: ✭ 284 (-10.41%)
Mutual labels:  graphql, apollo
Apollo Cache Redux
Redux cache for Apollo Client 2.0. This project is no longer maintained.
Stars: ✭ 179 (-43.53%)
Mutual labels:  graphql, apollo
Next React Graphql Apollo Hooks
React, Apollo, Next.js, GraphQL, Node.js, TypeScript high performance boilerplate with React hooks GraphQL implementation and automatic static type generation
Stars: ✭ 186 (-41.32%)
Mutual labels:  graphql, apollo
React Apollo Form
Build React forms based on GraphQL APIs.
Stars: ✭ 178 (-43.85%)
Mutual labels:  graphql, apollo
Modern Graphql Tutorial
📖 A simple and easy GraphQL tutorial to get started with GraphQL.
Stars: ✭ 219 (-30.91%)
Mutual labels:  graphql, apollo
Scalable React Typescript Boilerplate
⭐️ Scalable micro-framework featuring React and TypeScript
Stars: ✭ 174 (-45.11%)
Mutual labels:  graphql, apollo
Sqldatasource
SQL DataSource for Apollo GraphQL projects
Stars: ✭ 176 (-44.48%)
Mutual labels:  graphql, apollo
Graphql Shield
🛡 A GraphQL tool to ease the creation of permission layer.
Stars: ✭ 3,121 (+884.54%)
Mutual labels:  graphql, apollo
Ssr Sample
A minimum sample of Server-Side-Rendering, Single-Page-Application and Progressive Web App
Stars: ✭ 285 (-10.09%)
Mutual labels:  graphql, apollo

Artemis

Build dart types from GraphQL schemas and queries

View at pub.dev Test PRs Welcome Star on GitHub Fork on GitHub Discord

Check the beta branch for the bleeding edge (and breaking) stuff.

Artemis is a code generator that looks for schema.graphql (GraphQL SDL - Schema Definition Language) and *.graphql files and builds .graphql.dart files typing that query, based on the schema. That's similar to what Apollo does (Artemis is his sister anyway).


Installation

Add the following to your pubspec.yaml file to be able to do code generation:

dev_dependencies:
  artemis: '>=6.0.0 <7.0.0'
  build_runner: ^1.10.4
  json_serializable: ^3.5.0

The generated code uses the following packages in run-time:

dependencies:
  artemis: '>=6.0.0 <7.0.0' # only if you're using ArtemisClient!
  json_annotation: ^3.1.0
  equatable: ^1.2.5
  meta: '>=1.0.0 <2.0.0' # only if you have non nullable fields
  gql: '>=0.12.3 <1.0.0'

Then run:

pub packages get

or

flutter packages get

Now Artemis will generate the API files for you by running:

pub run build_runner build

or

flutter pub run build_runner build

Configuration

Artemis offers some configuration options to generate code. All options should be included on build.yaml file on the root of the project:

targets:
  $default:
    builders:
      artemis:
        options:
          # custom configuration options!

⚠️ Make sure your configuration file is called build.yaml (with .yaml extension, not .yml)!

Option Default value Description
generate_helpers true If Artemis should generate query/mutation helper GraphQLQuery subclasses.
scalar_mapping [] Mapping of GraphQL and Dart types. See Custom scalars.
schema_mapping [] Mapping of queries and which schemas they will use for code generation. See Schema mapping.
fragments_glob null Import path to the file implementing fragments for all queries mapped in schema_mapping. If it's assigned, fragments defined in schema_mapping will be ignored.
ignore_for_file [] The linter rules to ignore for artemis generated files.

It's important to remember that, by default, build will follow Dart's package layout conventions, meaning that only some folders will be considered to parse the input files. So, if you want to reference files from a folder other than lib/, make sure you've included it on sources:

targets:
  $default:
    sources:
      - lib/**
      - graphql/**
      - data/**
      - schema.graphql

Schema mapping

By default, Artemis won't generate anything. That's because your queries/mutations should be linked to GraphQL schemas. To configure it, you need to point a schema_mapping to the path of those queries and schemas:

targets:
  $default:
    builders:
      artemis:
        options:
          schema_mapping:
            - output: lib/graphql_api.dart
              schema: lib/my_graphql_schema.graphql
              queries_glob: lib/**.graphql

Each SchemaMap is configured this way:

Option Default value Description
output Relative path to output the generated code. It should end with .graphql.dart or else the generator will need to generate one more file.
schema Relative path to the GraphQL schema.
queries_glob Glob that selects all query files to be used with this schema.
naming_scheme pathedWithTypes The naming scheme to be used on generated classes names. pathedWithTypes is the default for retrocompatibility, where the names of previous types are used as prefix of the next class. This can generate duplication on certain schemas. With pathedWithFields, the names of previous fields are used as prefix of the next class and with simple, only the actual GraphQL class name is considered.
type_name_field __typename The name of the field used to differentiatiate interfaces and union types (commonly __typename or __resolveType). Note that __typename field are not added automatically to the query. If you want interface/union type resolution, you need to manually add it there.

See examples for more information and configuration options.

Custom scalars

If your schema uses custom scalars, they must be defined on build.yaml. If it needs a custom parser (to decode from/to json), the custom_parser_import path must be set and the file must implement both fromGraphQL___ToDart___ and fromDart___toGraphQL___ constant functions.

targets:
  $default:
    builders:
      artemis:
        options:
          scalar_mapping:
            - custom_parser_import: 'package:graphbrainz_example/coercers.dart'
              graphql_type: Date
              dart_type: DateTime

If your custom scalar needs to import Dart libraries, you can provide it in the config as well:

targets:
  $default:
    builders:
      artemis:
        options:
          scalar_mapping:
            - custom_parser_import: 'package:graphbrainz_example/coercers.dart'
              graphql_type: BigDecimal
              dart_type:
                name: Decimal
                imports:
                  - 'package:decimal/decimal.dart'

Each ScalarMap is configured this way:

Option Default value Description
graphql_type The GraphQL custom scalar name on schema.
dart_type The Dart type this custom scalar should be converted from/to.
custom_parser_import null Import path to the file implementing coercer functions for custom scalars. See Custom scalars.

See examples for more information and configuration options.

Articles and videos

  1. Ultimate toolchain to work with GraphQL in Flutter
  2. Awesome GraphQL

ArtemisClient

If you have generate_helpers, Artemis will create a subclass of GraphQLQuery for you, this class can be used in conjunction with ArtemisClient.

final client = ArtemisClient('/graphql');
final gitHubReposQuery = MyGitHubReposQuery();
final response = await client.execute(gitHubReposQuery);

ArtemisClient adds type-awareness around Link from package:gql/link. You can create ArtemisClient from any Link using ArtemisClient.fromLink.

Check the examples to see how to use it in details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].