On the graphql-code-generator website, choose the Operations Types (near-operation-file) demo and delete the query from operation.graphql, so that the file's body is simply:
fragment UserFields on User {
id
username
role
}
Expected:operation.generated.tsx should have (something like)—
import * as Types from './types';
import { gql } from '@apollo/client';
export type FindUserQueryVariables = Types.Exact<{
userId: Types.Scalars['ID'];
}>;
export type UserFieldsFragment = (
{ __typename?: 'User' }
& Pick<Types.User, 'id' | 'username' | 'role'>
);
export const UserFieldsFragmentDoc = gql`
fragment UserFields on User {
id
username
role
}
`;
Actual: it has an error:
GraphQLDocumentError: Fragment "UserFields" is never used.
at operation.graphql:1:1
Why it matters: it's useful to be able to programmatically generate fragment-only types for use with components, to be imported e.g. via #import. Fragment-only documents should be allowed!
Related: #1532
I will likely have a PR up for this sooner rather than later; if you have initial context or input, please let me know!
I think this is an issue on codegen side because it checks if fragments are used or not. So closing it for now. It'd be better to track this on Codegen repo.
Reproduction:
On the graphql-code-generator website, choose the Operations Types (near-operation-file) demo and delete the query from
operation.graphql
, so that the file's body is simply:Expected:
operation.generated.tsx
should have (something like)—Actual: it has an error:
Why it matters: it's useful to be able to programmatically generate fragment-only types for use with components, to be imported e.g. via
#import
. Fragment-only documents should be allowed!Related: #1532
I will likely have a PR up for this sooner rather than later; if you have initial context or input, please let me know!