Apollo Upload Scalar type is TypeScript 'any' #4320
-
|
Hi, Sorry if I'm missing something about this, but I'm a bit confused around using the I'm trying to make my frontend upload an image through my GraphQL server, however when I write my mutation to upload this image: mutation SetThumbnail($slug: String!, $upload: Upload!) {
setThumbnail(slug: $slug, upload: $upload) {
name
}
}And then generate using this query, it results in this: export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
Upload: any;
};Specifically overwrite: true
schema:
- "../graphql/graph/schema.graphqls"
- scalar Upload
documents: ["./src/**/*.tsx", "./src/**/*.ts", "./src/**/*.graphql"]
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
skipTypename: false
withHooks: true
withHOC: false
withComponent: falseSorry if this is a mistake on my end, here's some details around my environment: "@graphql-codegen/cli": "1.15.3",
"@graphql-codegen/introspection": "1.15.3",
"@graphql-codegen/typescript": "1.15.3",
"@graphql-codegen/typescript-operations": "1.15.3",
"@graphql-codegen/typescript-react-apollo": "1.15.3",Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
For people that would like a bit more specific answer, you can do it like this: {
//..
config: {
scalars: {
Upload: "Promise<GraphQLFileUpload>", // this
},
},
plugins: [
//...
{
add: `
import { ReadStream } from "fs-capacitor";
interface GraphQLFileUpload {
filename: string;
mimetype: string;
encoding: string;
createReadStream(options?:{encoding?: string, highWaterMark?: number}): ReadStream;
}`,
},
],
}; |
Beta Was this translation helpful? Give feedback.
Uploadis a custom scalar that is not part of GraphQL Specification. Like all other custom scalars,Uploadisanyin generated code. You can usescalarsfield to provide your own TS definition for custom scalars; (e.g., for frontend, you can useUpload: File)https://graphql-code-generator.com/docs/plugins/typescript#scalars