Comments (2)
@zhigang1992 I tried something similar in the past but was not able to make it work for union/interface types and didn't have the time to work on it since. I will take a look how graphql-zeus
managed to solve this issue.
from graphql-typed-client.
Here is a gist of it
export interface UserRequest {
name?: boolean
age?: boolean
blogs?:
| [{ first?: number }, BlogRequest]
| BlogRequest
__typename?: boolean
__scalar?: boolean
}
export interface UserOutput {
name: String
age: number
blogs: BlogOutput[];
__typename: 'UserOutput'
}
export interface BlogRequest {
title?: boolean;
article?: boolean;
createdAt?: boolean;
__typename?: boolean
__scalar?: boolean
}
export interface BlogOutput {
title: string;
article: string;
createdAt: string;
__typename: 'BlogOutput'
}
type Anify<T> = { [P in keyof T]?: any };
type LastMapTypeSRCResolver<Output, Filter> = Output extends undefined
? undefined
: Output extends Array<infer AR>
? LastMapTypeSRCResolver<AR, Filter>[]
: Filter extends boolean
? Output
: MapType<Output, Filter>;
type MapType<Output extends Anify<Filter>, Filter> = Output extends boolean ? boolean : {
[Key in keyof Filter]: Filter[Key] extends [any, infer PAYLOAD]
? LastMapTypeSRCResolver<Output[Key], PAYLOAD>
: LastMapTypeSRCResolver<Output[Key], Filter[Key]>;
}
type Execute<Request, Output> = <Z extends Request>(subFields: Z) => MapType<Output, Z>
let execute: Execute<UserRequest, UserOutput>
const a = execute({ name: true, blogs: {title: true} });
a.name;
a.blogs[0].title;
a.age // type script complains
But I don't have enough knowledge on this code base to create a PR yet.
from graphql-typed-client.
Related Issues (20)
- apply typeMapper to input types in variables HOT 1
- Execution result type includes the full schema HOT 15
- support glob pattern for schema loading
- use 'unknown' instead of 'any'
- "TypeError: Object(...) is not a function" exception when importing the generated client in Next.JS app HOT 2
- Cli process always is finished with 0 code HOT 1
- Prettier dependency HOT 7
- GraphQL Aliases HOT 4
- Suggestion: Generate client from TypeGraphql models HOT 2
- 'Observable' refers to a value, but is being used as a type here.
- Question/FR: How to get graphql query string? HOT 2
- Reduce bundle size HOT 1
- replace ws with isomorphic-ws for subscription in browser HOT 2
- graphql subscription is not working
- Custom scalar type mapping does not work with relative paths on Windows
- Generated code can have implicit any
- Don't delete the whole content of the output folder
- Comparison of this library with graphql-zeus?
- Serialization of array of custom scalars fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-typed-client.