dotansimha / dotansimha/graphql-code-generator-community
Typescript-urql doesn't remove all export identifiers when specifying `noExport: true`
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
When I use the plugin `typescript-urql` and specify `noExport: true` it doesn't get rid of all export indentifiers.
Another great option would be `hooksExportOnly` or something like that where the behavior would be to only add export indentifiers to hooks, since I'm only planning on importing hooks in my code and not importing .e.g. types. It's a bit frustrating since eslint will complain of unused export statements on the exported types, because I'm not importing those types, only hooks.
This is my codegen configuration as a config field in my `package.json` file:
```JSON
"codegen": {
"watch": true,
"schema": "../server/schema.graphql",
"documents": "src/graphql/**/*.graphql",
"generates": {
"src/graphql/hooks.ts": {
"config": {
"defaultScalarType": "string"
},
"plugins": [
{
"typescript": {
"onlyOperationTypes": true,
"noExport": true
}
},
{
"typescript-operations": {
"onlyOperationTypes": true,
"noExport": true
}
},
{
"typescript-urql": {
"noExport": true
}
}
]
}
}
}
```
And this is what it generates:
```TypeScript
/* eslint-disable */
/* eslint-enable import/no-unused-modules */
import gql from 'graphql-tag';
import * as Urql from 'urql';
type Maybe = T | null;
type Exact = { [K in keyof T]: T[K] };
type MakeOptional = Omit & { [SubKey in K]?: Maybe };
type MakeMaybe = Omit & { [SubKey in K]: Maybe };
export type Omit = Pick>;
/** All built-in and custom scalars, mapped to their actual values */
type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
/** A field whose value conforms to the standard internet email address format as specified in RFC822: https://www.w3.org/Protocols/rfc822/. */
EmailAddress: string;
/** A field whose value conforms to the standard URL format as specified in RFC3986: https://www.ietf.org/rfc/rfc3986.txt. */
URL: string;
};
type RegisterUserInput = {
email: Scalars['EmailAddress'];
image: Scalars['URL'];
name: Scalars['String'];
password: Scalars['String'];
};
type RegisterUserMutationVariables = Exact<{
userInput: RegisterUserInput;
}>;
type RegisterUserMutation = { __typename?: 'Mutation', RegisterUser: { __typename?: 'User', email: string, image: string } };
type UsersQueryVariables = Exact<{ [key: string]: never; }>;
type UsersQuery = { __typename?: 'Query', users: Array<{ __typename?: 'User', id: string, name: string }> };
const RegisterUserDocument = gql`
mutation RegisterUser($userInput: RegisterUserInput!) {
RegisterUser(input: $userInput) {
email
image
}
}
`;
export function useRegisterUserMutation() {
return Urql.useMutation(RegisterUserDocument);
};
const UsersDocument = gql`
query Users {
users {
id
name
}
}
`;
export function useUsersQuery(options: Omit, 'query'> = {}) {
return Urql.useQuery({ query: UsersDocument, ...options });
};
```
As you can see it generates the following type:
`export type Omit = Pick>;`
Which I don't want to export, but I still would like to keep the hooks at the bottom of the file exported!
Also I know I have to use the `add` plugin to add the eslint comments at the top of the file.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.