Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(condo): INFRA-517 added script for generating client utils #5264

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Alllex202
Copy link
Contributor

@Alllex202 Alllex202 commented Sep 19, 2024

  • bump @graphql-codegen/cli to v5
  • add script for generating client utils
  • add example query and utils

How to add some queries for client application

  1. Add a queries for the desired scheme to the file /domains/<YOUR_DOMAIN>/queries/<YOUR_SCHEMA>.graphql, like this:
query authenticatedUser {
    authenticatedUser {
        id
        name
        type
    }
}
  1. Run command:
yarn maketypes
  1. Ready-made utilities for use on the client (on the path /gql/index.ts) and some auxiliary types (on the path /gql/operation.types.ts) will be generated. In addition, schema.ts and schema.graphql will be updated as usual
  2. Now you can use ethylites in your code on the client, like this:
// import utils
import { 
    useAuthenticatedUserQuery, 
    useAuthenticatedUserLazyQuery
} from '@/gql'

// import types
import type { 
    AuthenticatedUserQueryVariables,
    AuthenticatedUserQuery, 
    AuthenticatedUserQueryHookResult, 
    AuthenticatedUserLazyQueryHookResult, 
    AuthenticatedUserQueryResult,
} from '@/gql'
  1. While developing, you also run automatic updates to client utilities and types:
yarn dev

Or if you want run separately:

types:watch

@Alllex202 Alllex202 added 👶 small Easy to review changes up to 50 lines of code ✋🙂 Review please Comments are resolved, take a look, please 😵‍💫 dependencies Pull requests that update a dependency file / yarn.lock labels Sep 19, 2024

const CodegenCommentPlugin = {
add: {
content: '// Autogenerated file by @graphql-codegen/cli\n',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
content: '// Autogenerated file by @graphql-codegen/cli\n',
content: [
'// This file is autogenerated by @graphql-codegen/cli\n',
'// Do not edit / add anything manually, since it will be overridden by codegen'
],

@@ -17,7 +17,7 @@
"migrate": "./../../bin/kmigrator.py migrate",
"migrate:down": "./../../bin/kmigrator.py down",
"migrate:unlock": "./../../bin/kmigrator.py unlock",
"maketypes": "mkdirp dist/admin && DISABLE_NEXT_APP=true node ./../../bin/create-graphql-schema.js && graphql-codegen -c codegen.yaml",
"maketypes": "mkdirp dist/admin && DISABLE_NEXT_APP=true node ./../../bin/create-graphql-schema.js && graphql-codegen -c codegen.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about dev script to watch for .graphql file changes?

const options = { ...defaultOptions, ...baseOptions }
return Apollo.useLazyQuery<Types.AuthenticatedUserQuery, Types.AuthenticatedUserQueryVariables>(AuthenticatedUserDocument, options)
}
export type AuthenticatedUserQueryHookResult = ReturnType<typeof useAuthenticatedUserQuery>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, types are also here :(
So, naming now is a bit confusing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You better ask someone else opinion here...

For me its a bit too nested route.

(Also not the biggest fan of gql folder, since it's now duplicate of gql.js and can be missunderstood later

@Alllex202 Alllex202 force-pushed the feat/condo/INFRA-517/client-utils-generation branch from 74e57ae to 59ec3af Compare September 20, 2024 10:16
@Alllex202 Alllex202 added 🔬 WIP Not intended to be merged right now, it is a work in progress and removed ✋🙂 Review please Comments are resolved, take a look, please labels Sep 23, 2024
@Alllex202 Alllex202 force-pushed the feat/condo/INFRA-517/client-utils-generation branch from 4658e7d to 75b09c4 Compare October 3, 2024 08:36
@Alllex202 Alllex202 force-pushed the feat/condo/INFRA-517/client-utils-generation branch from 75b09c4 to 5226478 Compare October 3, 2024 16:03
Copy link

sonarcloud bot commented Oct 3, 2024

@Alllex202 Alllex202 added ✋🙂 Review please Comments are resolved, take a look, please and removed 🔬 WIP Not intended to be merged right now, it is a work in progress labels Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😵‍💫 dependencies Pull requests that update a dependency file / yarn.lock ✋🙂 Review please Comments are resolved, take a look, please 👶 small Easy to review changes up to 50 lines of code
Development

Successfully merging this pull request may close these issues.

2 participants