graphql/codegen/plugins/typescript/typescript-react-apollo #8641
Replies: 13 comments 10 replies
-
a lot of the code examples have the following typo:
where |
Beta Was this translation helpful? Give feedback.
-
When enabling |
Beta Was this translation helpful? Give feedback.
-
Do we have already the possibility to generate fragments from fragment UserFragment on User { id firstName lastName email } Would gen: export const UserFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserFragment"} /* ... */ ]};
export type UserFragment = { readonly __typename?: 'User', readonly id: string, readonly firstName: string, readonly lastName: string, readonly email };
export const useUserFragment = (id: string) => useFragment_experimental<UserFragment>({
fragment: UserFragmenttDoc,
fragmentName: 'UserFragment',
from: { __typename: 'User', id },
}); That would be such useful 🙏 |
Beta Was this translation helpful? Give feedback.
-
Please improve the documentation with:
I try to find how I can separate mutation, and queries for the EDIT: Have to patch the generator as follow:
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to use
|
Beta Was this translation helpful? Give feedback.
-
Is there a place we can see the release notes for updates for this plugin? It's super helpful thank you! |
Beta Was this translation helpful? Give feedback.
-
With this plugin, you can generate conveinvent functions for hooks, like: But you don't always use hooks, especially when you fetch on server, like in server-side components, on nextjs fetchers like getStaticPaths. Is it possible to generate function the same, that would allow me to do same using async:
So far im writing helpers functions, like: const fetchTest = (options: ...) => client.query<TestQuery, TestQueryVariables>)({
query: FetchLayoutDocument
) But I wonder if it's possible to do it automatically. If not, I'd love to try contributting to this plugin to have that feature. |
Beta Was this translation helpful? Give feedback.
-
@ThePatriczek I'm looking to leverage generated suspense queries in my project. I've installed src/apollo-client/generated/client-operations.tsx:
schema:
- ./src/server/graphql/helpers/type-defs/*.ts
- ./src/server/graphql/**/schema.ts
documents:
- ./src/apollo-client/**/*.graphql
- ./src/app/**/*.graphql
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
- add:
content: "/* eslint-disable */"
config:
scalars:
Date: string
DateTime: string
Tz: string
Email: string
PhoneNumber: string
Url: string
Coordinates: string Query looks like this: query GetBusiness {
business {
defaultBusiness {
payload {
id
name
}
}
}
} And output looks like this: export function useGetBusinessQuery(baseOptions?: Apollo.QueryHookOptions<GetBusinessQuery, GetBusinessQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<GetBusinessQuery, GetBusinessQueryVariables>(GetBusinessDocument, options);
}
export function useGetBusinessLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetBusinessQuery, GetBusinessQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<GetBusinessQuery, GetBusinessQueryVariables>(GetBusinessDocument, options);
}
export type GetBusinessQueryHookResult = ReturnType<typeof useGetBusinessQuery>;
export type GetBusinessLazyQueryHookResult = ReturnType<typeof useGetBusinessLazyQuery>;
export type GetBusinessQueryResult = Apollo.QueryResult<GetBusinessQuery, GetBusinessQueryVariables>; Is there something I'm missing to generate the suspense queries? Thanks! |
Beta Was this translation helpful? Give feedback.
-
I do NOT want to generate suspense query( default: generate on)
import type { CodegenConfig } from '@graphql-codegen/cli'
const config: CodegenConfig = {
schema: 'YOUR_SCHEMA_HERE',
documents: './src/**/*.graphql',
generates: {
'./generated-types.ts': {
plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo']
}
}
}
export default config |
Beta Was this translation helpful? Give feedback.
-
Is there a way the generated react hooks not to include the |
Beta Was this translation helpful? Give feedback.
-
Are there plans to add: |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use it in combination with typed-document-node. "src/generated/types.ts": {
plugins: [
"typescript",
"typescript-operations",
"typed-document-node",
],
},
"src/generated/hooks.ts": {
plugins: ["typescript-react-apollo"],
config: {
documentMode: "external",
importDocumentNodeExternallyFrom: "./types",
},
preset: "import-types",
presetConfig: {
typesPath: "./types",
},
}, However, the document node exported with Document suffix but in the hooks used without the suffix. |
Beta Was this translation helpful? Give feedback.
-
graphql/codegen/plugins/typescript/typescript-react-apollo
GraphQL Code Generator Documentation
https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-apollo
Beta Was this translation helpful? Give feedback.
All reactions