GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — How to handle generic Error interface in Union result · Issue #235 · comigor/artemis
This repository was archived by the owner on Oct 2, 2024. It is now read-only.
This repository was archived by the owner on Oct 2, 2024. It is now read-only.
How to handle generic Error interface in Union result #235Copy link Copy link Open Labels bugSomething isn't working DescriptionOur schema looks like this: type Query { courier(code: String!): CourierResult! } union CourierResult = Courier | CourierNotFoundError | InternalServerError type Courier { name: String! code: String! picture: String! } interface Error { message: String! } type InternalServerError implements Error { message: String! } type CourierNotFoundError implements Error { message: String! } This schema was inspired by this blog post: https://blog.logrocket.com/handling-graphql-errors-like-a-champ-with-unions-and-interfaces/ When consuming this schema, we use the following query: query courier($code: String!) { courier(code: $code) { __typename ... on Courier { name code picture } ... on CourierNotFoundError { message } ... on Error { message } } } This way, What Artemis currently does is the following: class Courier$Query$CourierResult with EquatableMixin { Courier$Query$CourierResult(); factory Courier$Query$CourierResult.fromJson(Map<String, dynamic> json) { switch (json['__typename'].toString()) { case r'Courier': return Courier$Query$CourierResult$Courier.fromJson(json); case r'CourierNotFoundError': return Courier$Query$CourierResult$CourierNotFoundError.fromJson(json); case r'Error': return Courier$Query$CourierResult$Error.fromJson(json); default: } return _$Courier$Query$CourierResultFromJson(json); } // ... } When receiving a What I propose is to add some kind of logic for detecting types which extend an interface, and queries which use interfaces. I suppose I can manually create a custom parser for this. Specs build.yaml:targets: $default: builders: artemis: options: schema_mapping: - output: lib/modules/graphql/api.graphql.dart schema: lib/modules/graphql/schema.graphql queries_glob: lib/modules/graphql/queries/**.graphql Artemis output:# Please paste the output of $ flutter pub run build_runner build --verbose #or $ pub run build_runner build --verbose GraphQL schema:type Query { courier(code: String!): CourierResult! } union CourierResult = Courier | CourierNotFoundError | InternalServerError type Courier { name: String! code: String! picture: String! } interface Error { message: String! } type InternalServerError implements Error { message: String! } type CourierNotFoundError implements Error { message: String! } GraphQL query:query courier($code: String!) { courier(code: $code) { __typename ... on Courier { name code picture } ... on CourierNotFoundError { message } ... on Error { message } } } Reacted by Thomas Leberbauer Activity
MetadataMetadataAssigneesLabelsbugSomething isn't working TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |