What is @graphql-codegen/import-types-preset?
@graphql-codegen/import-types-preset is a preset for GraphQL Code Generator that allows you to import types from other files. This is particularly useful when you want to share types across different parts of your application or when you want to keep your type definitions organized in separate files.
What are @graphql-codegen/import-types-preset's main functionalities?
Importing Types from Other Files
This feature allows you to import types from a specified path. In this example, types are imported from the '../types' directory.
```json
{
"generates": {
"./src/generated-types.ts": {
"plugins": [
"typescript",
"typescript-operations"
],
"preset": "import-types",
"presetConfig": {
"typesPath": "../types"
}
}
}
}
```
Customizing Import Paths
This feature allows you to customize the namespace for imported types. In this example, the types are imported under the 'MyTypes' namespace.
```json
{
"generates": {
"./src/generated-types.ts": {
"plugins": [
"typescript",
"typescript-operations"
],
"preset": "import-types",
"presetConfig": {
"typesPath": "../types",
"importTypesNamespace": "MyTypes"
}
}
}
}
```
Other packages similar to @graphql-codegen/import-types-preset
graphql-codegen-typescript
graphql-codegen-typescript is a plugin for GraphQL Code Generator that generates TypeScript typings for your GraphQL schema and operations. Unlike @graphql-codegen/import-types-preset, it does not focus on importing types from other files but rather on generating types directly from your GraphQL schema.
graphql-codegen-typescript-operations
graphql-codegen-typescript-operations is another plugin for GraphQL Code Generator that generates TypeScript types for your GraphQL operations (queries, mutations, subscriptions). It complements @graphql-codegen/import-types-preset by focusing on operation types rather than type imports.
graphql-codegen-typescript-resolvers
graphql-codegen-typescript-resolvers is a plugin for GraphQL Code Generator that generates TypeScript types for your GraphQL resolvers. It is similar to @graphql-codegen/import-types-preset in that it helps organize your types, but it focuses specifically on resolver types.