Open smmoosavi opened 4 years ago
I’m not sure. Maybe @alloy can answer you.
can you provide some example of this?
is this like enums https://github.com/relay-tools/relay-compiler-language-typescript/issues/164?
or custom scalar https://github.com/relay-tools/relay-compiler-language-typescript/issues/129?
or custom scalar #129?
custom scalar is ok.
is this like enums #164?
this enum type is generated for Label_label
fragment. but I need some global file that contains all graphql enum types
for example, apollo tooling is generating a file that contained all enum types.
schema:
enum Color {
BLUE
GREEN
RED
}
enum Direction {
Right
Left
}
apollo client:codegen --globalTypesFile=src/globalTypes.ts
the generated file is independent of any query or fragment in the code and only depends on the schema file.
generated filesrc/globalTypes.ts
:
export enum GenerationType {
BLUE = "BLUE",
GREEN = "GREEN",
RED = "RED",
}
export enum Direction {/*..*/}
// and all other enums defined in the schema file
for the relay, it would be like src/globalTypes.ts
:
export type Color = "BLUE" | "GREEN" | "RED" | "%future added value";
export type Direction = "..."
for example, the ColorSelector
component doesn't have any fragment or query. but it needs Color
enum. and it shouldn't depend on any of the other usages that have the enum definitions.
you want something like this
RelayGraphQLEnumsGenerator
is only for Flow
right now
can you try implement this to Typescript?
you want something like this
yes. it is what I want (I assume schema argument is all defined types in graphql)
can you try to implement this to Typescript?
yes, I can. flow and typescript output is almost equal in this case. except for the header part.
but I don't know at which file it should be written. or where and how this function should be used. (integrated with relay-compiler-language-typescript and relay-compiler)
Me and @smmoosavi wrote a package for this purpose: relay-enum-generator
Great to hear, can you add this to relay documentation?
@sibelius Where should I add this to?
Check Facebook/relay repo, there is a docusaurus there, this could be close to type emission guide
How about just type aliases? for example: export type UUID = string; The type is of course not imported by all the generated files making them fail the compilation.
we can generate global types (like enums) with apollo tooling. you can see
--globalTypesFile
option.can we do the same thing with relay compiler and generate global types file.
tnx