Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalar input/output related CHANGELOG with new recommended codegen config #9491

Closed
wants to merge 5 commits into from
Closed
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
21 changes: 21 additions & 0 deletions packages/plugins/other/visitor-plugin-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@
};
```

Here's the recommended config when generating server types with `typescript-resolvers`:

```ts
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
ID: {
input: 'string',
output: 'string | number'
},
}
},
},
},
};
```

***

Config changes:
Expand Down
21 changes: 21 additions & 0 deletions packages/plugins/typescript/operations/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@
};
```

Here's the recommended config when generating server types with `typescript-resolvers`:

```ts
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
ID: {
input: 'string',
output: 'string | number'
},
}
},
},
},
};
```

***

Config changes:
Expand Down
21 changes: 21 additions & 0 deletions packages/plugins/typescript/resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@
};
```

Here's the recommended config when generating server types with `typescript-resolvers`:

```ts
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
ID: {
input: 'string',
output: 'string | number'
},
}
},
},
},
};
```

***

Config changes:
Expand Down
21 changes: 21 additions & 0 deletions packages/plugins/typescript/typescript/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@
};
```

Here's the recommended config when generating server types with `typescript-resolvers`:

```ts
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
ID: {
input: 'string',
output: 'string | number'
},
}
},
},
},
};
```

***

Config changes:
Expand Down
16 changes: 15 additions & 1 deletion website/src/pages/docs/guides/graphql-server-apollo-yoga.mdx
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also update the GraphQL server guides with recommended scalars config

Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ const config: CodegenConfig = {
schema: 'schema.graphql',
generates: {
'./resolvers-types.ts': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
ID: {
input: 'string',
output: 'string | number'
},
},
useIndexSignature: true,
},
plugins: ['typescript', 'typescript-resolvers'],
},
},
};
Expand All @@ -96,6 +102,14 @@ const config: CodegenConfig = {
generates: {
'./resolvers-types.ts': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
ID: {
input: 'string',
output: 'string | number'
},
},
},
},
},
};
Expand Down
5 changes: 3 additions & 2 deletions website/src/pages/docs/guides/react-vue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ export default config
**Usage with `@tanstack/react-query`**

If you are using `@tanstack/react-query`, we recommend using it with `graphql-request@^5.0.0` to get the best developer experience.
<br/>
If you are willing to provide your own fetcher, you can directly jump to the ["Appendix I: React Query with a custom fetcher setup"](#appendix-i-react-query-with-a-custom-fetcher-setup) and continue the guide once React Query is properly setup.
Comment on lines -133 to -134
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why prettier didn't catch this in the previous PRs 🤔
Running yarn prettier fixes this though.


If you are willing to provide your own fetcher, you can directly jump to the ["Appendix I: React Query with a custom fetcher
setup"](#appendix-i-react-query-with-a-custom-fetcher-setup) and continue the guide once React Query is properly setup.

</Callout>

Expand Down
20 changes: 18 additions & 2 deletions website/src/pages/plugins/typescript/typescript-resolvers.mdx
Copy link
Collaborator Author

@eddeee888 eddeee888 Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this page is rendered, the PluginApiDocs is at the top. Readers have to scroll quite far down to see the usage example.

I wonder if we should switch it, so the Usage example is first, then PluginApiDocs is at the bottom?

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You can find [a blog post we wrote about using and customizing this plugin here]

</Callout>

Run `graphql-codegen` as usual, with this new plugin:
Run `graphql-codegen` with `typescript-resolvers` plugin and the following config:

```ts filename="codegen.ts"
import type { CodegenConfig } from '@graphql-codegen/cli'
Expand All @@ -42,7 +42,16 @@ const config: CodegenConfig = {
schema: 'schema.json',
generates: {
'./src/resolvers-types.ts': {
plugins: ['typescript', 'typescript-resolvers']
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars: {
// This option is required to match how GraphQL servers handle ID scalar
ID: {
input: 'string',
output: 'string | number'
}
}
}
Comment on lines +46 to +54
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this section with the new config.

}
}
}
Expand Down Expand Up @@ -79,6 +88,7 @@ const config: CodegenConfig = {
'./resolvers-types.ts': {
config: {
useIndexSignature: true
// ... other config options
},
plugins: ['typescript', 'typescript-resolvers']
}
Expand Down Expand Up @@ -108,6 +118,7 @@ const config: CodegenConfig = {
User: './models#UserModel',
Profile: './models#UserProfile'
}
// ... other config options
},
plugins: ['typescript', 'typescript-resolvers']
}
Expand Down Expand Up @@ -150,6 +161,7 @@ const config: CodegenConfig = {
enumValues: {
Color: './enums#ColorsCode'
}
// ... other config options
},
plugins: ['typescript', 'typescript-resolvers']
}
Expand Down Expand Up @@ -196,6 +208,7 @@ const config: CodegenConfig = {
BLUE: '#0000FF'
}
}
// ... other config options
},
plugins: ['typescript', 'typescript-resolvers']
}
Expand All @@ -217,6 +230,7 @@ const config: CodegenConfig = {
mappers: {
Color: './enums#ColorsCode'
}
// ... other config options
},
plugins: ['typescript', 'typescript-resolvers']
}
Expand Down Expand Up @@ -249,6 +263,7 @@ const config: CodegenConfig = {
...sharedMappers,
String: 'StringType'
}
// ... other config options
}
},
'resolvers-types-2.ts': {
Expand All @@ -258,6 +273,7 @@ const config: CodegenConfig = {
...sharedMappers,
String: 'StringType'
}
// ... other config options
}
}
}
Expand Down