dotansimha / dotansimha/graphql-code-generator-community
TypedDocumentNode for graphql-files-modules
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
I've written* a plugin that fills the same role as the `typescript-graphql-files-modules` plugin (importing .graphql files into typescript with graphql-loader or similar) but which types the exported operations with `TypedDocumentNode`s that integrate with the `typescript` plugin. There isn't, as far as I know, anything else in the `@graphql-codegen` ecosystem that integrates `TypedDocumentNode` with standalone graphql files like this.
- It wouldn't take much work to add a PR integrating the plugin into this repo or the main codegen repo. Config documentation and tests are already written.
- Alternatively, I could change the plugin's API a bit so it's backwards compatible with `typescript-graphql-files-modules` and then use it to replace that plugin entirely.
Would you be interested in a PR along these lines?
*Or really, forked from an [existing but out-of-date plugin](https://github.com/rubengrill/apollo-typed-documents).
---
So where the existing plugin generates this:
```typescript
declare module "*/UserOperations.gql" {
import { DocumentNode } from "graphql"
const defaultDocument: DocumentNode
export const NotificationPreference: DocumentNode
export const ExternalAccountStatus: DocumentNode
export const UserExternalAccountsStatus: DocumentNode
export const User: DocumentNode
export const UserProjects: DocumentNode
export const UserGet: DocumentNode
export const UsersList: DocumentNode
export const UsersCollection: DocumentNode
export const UserGetUserProjects: DocumentNode
export const UserSave: DocumentNode
export const UserSendInvitation: DocumentNode
export default defaultDocument
}
```
Mine generates this:
```typescript
declare module "*/UserOperations.gql" {
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
import { UserGetQuery, UserGetQueryVariables } from "graphql/schema";
export const UserGet: TypedDocumentNode;
import { UsersListQuery, UsersListQueryVariables } from "graphql/schema";
export const UsersList: TypedDocumentNode;
import { UsersCollectionQuery, UsersCollectionQueryVariables } from "graphql/schema";
export const UsersCollection: TypedDocumentNode;
import { UserGetUserProjectsQuery, UserGetUserProjectsQueryVariables } from "graphql/schema";
export const UserGetUserProjects: TypedDocumentNode;
import { UserSaveMutation, UserSaveMutationVariables } from "graphql/schema";
export const UserSave: TypedDocumentNode;
import { UserSendInvitationMutation, UserSendInvitationMutationVariables } from "graphql/schema";
export const UserSendInvitation: TypedDocumentNode;
}
```
The location of the schema definitions, the location of TypedDocumentNode itself, and many other things are configurable.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.