{"id":13475407,"url":"https://github.com/kazuyaseki/graphql-codegen-flutter-artemis-hooks","last_synced_at":"2025-03-23T14:31:04.702Z","repository":{"id":40409922,"uuid":"439410297","full_name":"kazuyaseki/graphql-codegen-flutter-artemis-hooks","owner":"kazuyaseki","description":"graphql-codegen plugin to generate type-safe, easy-to use hooks for Flutter","archived":false,"fork":false,"pushed_at":"2023-12-15T17:28:08.000Z","size":165,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T03:28:46.736Z","etag":null,"topics":["artemis","flutter","graphql","graphql-codegen"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kazuyaseki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-17T17:25:58.000Z","updated_at":"2023-01-02T13:18:07.000Z","dependencies_parsed_at":"2024-10-21T20:03:45.918Z","dependency_job_id":null,"html_url":"https://github.com/kazuyaseki/graphql-codegen-flutter-artemis-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazuyaseki","download_url":"https://codeload.github.com/kazuyaseki/graphql-codegen-flutter-artemis-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243680989,"owners_count":20330152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artemis","flutter","graphql","graphql-codegen"],"created_at":"2024-07-31T16:01:20.131Z","updated_at":"2025-03-23T14:31:04.303Z","avatar_url":"https://github.com/kazuyaseki.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# graphql-codegen-flutter-artemis-hooks\n\nThis is graphql-codegen plugin to generate type-safe, easy-to use Flutter artemis hooks.\nFor further detail, see \"What it generates\" section.\n\n## Prerequisite\n\nThis plugin assumes that you use the following packages\n\n- [flutter_hooks](https://pub.dev/packages/flutter_hooks)\n- [graphql_flutter](https://pub.dev/packages/graphql_flutter)\n- [artemis](https://pub.dev/packages/artemis)\n\n## How to use\n\n### Install\n\n```bash\nnpm i graphql-codegen-flutter-artemis-hooks\n```\n\n### Edit codegen.yml\n\nPlease specify path to the file generated by artemis\n\n```yml\nschema: your_schema_file.graphql\ndocuments: './your_project/**/*.graphql'\ngenerates:\n  your_project/generated_hooks.dart:\n    config:\n      artemisImportPath: package:your_project/your_artemis_generated/graphql_api.dart\n    plugins:\n      - graphql-codegen-flutter-artemis-hooks\n```\n\nthen run the codegens!!\n\n## What it generates\n\nfor instance, if you have defined GraphQL as following\n\n```graphql\nquery ExampleQuery {\n  objects {\n    id\n    name\n  }\n}\n\nmutation TestMutation($variable: String!) {\n  testMutation(variable: $variable) {\n    result\n  }\n}\n```\n\nand using this plugin would generate code like this.\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'package:flutter_hooks/flutter_hooks.dart';\nimport 'package:graphql_flutter/graphql_flutter.dart';\nimport 'package:gql/ast.dart';\nimport 'package:your_project/your_artemis_generated/graphql_api.dart';\n\nQueryResult useQuery\u003cDataType\u003e(BuildContext context, DocumentNode query,\n    [Map\u003cString, dynamic\u003e? variables]) {\n  final client = GraphQLProvider.of(context).value;\n  final state =\n      useState\u003cQueryResult\u003e(QueryResult(source: QueryResultSource.network));\n\n  useEffect(() {\n    late Future\u003cQueryResult\u003e promise;\n\n    if (variables != null) {\n      promise = client.query(\n        QueryOptions(document: query, variables: variables),\n      );\n    } else {\n      promise = client.query(\n        QueryOptions(document: query),\n      );\n    }\n    promise.then((result) {\n      state.value = result;\n    });\n\n    return () {};\n  }, []);\n  return state.value;\n}\n\nclass ExampleQuery$QueryReturnType {\n  bool isLoading;\n  OperationException? exception;\n  ExampleQuery$Query? data;\n\n  ExampleQuery$QueryReturnType(this.isLoading, this.exception, this.data);\n}\n\nExampleQuery$QueryReturnType useExampleQueryQuery\u003cDataType\u003e(BuildContext context) {\n  final result = useQuery\u003cExampleQuery$Query\u003e(context, EXAMPLE_QUERY_QUERY_DOCUMENT);\n  return ExampleQuery$QueryReturnType(result.isLoading, result.exception, result.data == null ? null : ExampleQuery$Query.fromJson(result.data!));\n}\n\nclass TestMutation$MutationReturnType {\n  bool isLoading;\n  OperationException? exception;\n  TestMutation$Mutation? data;\n\n  TestMutation$MutationReturnType(this.isLoading, this.exception, this.data);\n}\n\nTestMutation$MutationReturnType useTestMutationQuery\u003cDataType\u003e(BuildContext context, TestMutationArguments variables) {\n  final result = useQuery\u003cTestMutation$Mutation\u003e(context, TEST_MUTATION_MUTATION_DOCUMENT, variables.toJson());\n  return TestMutation$MutationReturnType(result.isLoading, result.exception, result.data == null ? null : TestMutation$Mutation.fromJson(result.data!));\n}\n```\n\nThen you can use the generated type-safe hooks as following.\n\n```dart\nclass PageWidget extends HookWidget {\n  const PageWidget({Key key}) : super(key: key);\n\n  @override\n  Widget build(BuildContext context) {\n    final queryResult = useExampleQueryQuery(context);\n    final mutationResult = useTestMutationQuery(context, TestMutationArguments(variable: \"\"));\n\n    return ...\n  }\n}\n```\n\n## Configuration\n\n- `artemisImportPath`: path to your generated file by artemis\n- `isNonNullSafety` (default: null): set this to `true` if you want to generate code that is not null safety\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazuyaseki%2Fgraphql-codegen-flutter-artemis-hooks/lists"}