Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/programmatic-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@graphql-codegen/plugin-helpers": "7.0.0",
"@graphql-codegen/typed-document-node": "7.0.0",
"@graphql-codegen/typescript": "6.0.1",
"@graphql-codegen/typescript-operations": "6.0.1",
"@graphql-codegen/typescript-operations": "6.0.2",
"@graphql-codegen/typescript-resolvers": "6.0.0",
"@graphql-tools/graphql-file-loader": "^8.1.12",
"@graphql-tools/load": "8.1.10",
Expand Down
9 changes: 9 additions & 0 deletions packages/plugins/typescript/operations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @graphql-codegen/typescript-operations

## 6.0.2

### Patch Changes

- [#10792](https://github.com/dotansimha/graphql-code-generator/pull/10792)
[`297c896`](https://github.com/dotansimha/graphql-code-generator/commit/297c8965c8f89a273a919b5f643d24ae02b5006d)
Thanks [@eddeee888](https://github.com/eddeee888)! - Fix `typescript-operations` incosistent
scalar overrides for native scalars

## 6.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/typescript/operations/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript-operations",
"version": "6.0.1",
"version": "6.0.2",
"type": "module",
"description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/typescript/operations/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
type: 'GraphQLScalarType',
node,
tsType:
(DEFAULT_INPUT_SCALARS[node.name]?.input ||
this.config.scalars?.[node.name]?.input.type) ??
this.config.scalars?.[node.name]?.input.type ??
DEFAULT_INPUT_SCALARS[node.name]?.input ??
'unknown',
useCases: {
variables: location === 'variables',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,89 @@ describe('TypeScript Operations Plugin - Default Scalar types', () => {
});

describe('TypeScript Operations Plugin - Custom Scalars', () => {
it('uses custom inline scalars for Input, Variables and Result', async () => {
const schema = buildSchema(/* GraphQL */ `
type Query {
user(input: UserInput!): User
}

input UserInput {
id: ID!
age: Int!
createdAt: DateTime!
metadata: JSON!
}

type User {
id: ID!
age: Int!
createdAt: DateTime!
metadata: JSON!
}

scalar DateTime
scalar JSON
`);
const document = parse(/* GraphQL */ `
query User(
$input: UserInput!
$id: ID!
$age: Int!
$createdAt: DateTime!
$metadata: JSON!
) {
user(input: $input) {
id
age
createdAt
metadata
}
}
`);

const result = mergeOutputs([
await plugin(
schema,
[{ document }],
{
scalars: {
ID: 'string',
Int: 'bigint',
DateTime: 'Date',
},
},
{ outputFile: '' },
),
]);

expect(result).toMatchInlineSnapshot(`
"/** Internal type. DO NOT USE DIRECTLY. */
type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
/** Internal type. DO NOT USE DIRECTLY. */
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
export type UserInput = {
id: string;
age: bigint;
createdAt: Date;
metadata: unknown;
};

export type UserQueryVariables = Exact<{
input: UserInput;
id: string;
age: bigint;
createdAt: Date;
metadata: unknown;
}>;


export type UserQuery = { user: { id: string, age: bigint, createdAt: Date, metadata: unknown } | null };
"
`);

validateTs(result, undefined, undefined, undefined, undefined, true);
});

it('imports external custom scalar correctly when used in Result SelectionSet', async () => {
const schema = buildSchema(/* GraphQL */ `
type Query {
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@graphql-codegen/typescript-mongodb": "4.0.2",
"@graphql-codegen/typescript-msw": "4.0.1",
"@graphql-codegen/typescript-nhost": "1.0.1",
"@graphql-codegen/typescript-operations": "6.0.1",
"@graphql-codegen/typescript-operations": "6.0.2",
"@graphql-codegen/typescript-react-apollo": "4.4.2",
"@graphql-codegen/typescript-react-query": "4.1.0",
"@graphql-codegen/typescript-resolvers": "6.0.0",
Expand Down
Loading