Skip to content

Commit 9ff931c

Browse files
committed
added composable and readme example to it
1 parent 72c0829 commit 9ff931c

9 files changed

Lines changed: 50 additions & 8 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ Zeus syntax ( type-safe 😋 )
8181
}
8282
```
8383

84+
## New! Composables
85+
```ts
86+
import {
87+
Gql,
88+
ComposableSelector,
89+
} from './zeus/index.js';
90+
91+
const withComposable = <T extends ComposableSelector<'Card'>, Z extends T>(id: string, rest: Z | T) =>
92+
Gql('query')({
93+
cardById: [{ cardId: id }, rest],
94+
});
95+
const c1result = await withComposable('12', {
96+
id: true,
97+
});
98+
const c2result = await withComposable('12', {
99+
Defense: true,
100+
Attack: true,
101+
});
102+
```
103+
104+
Both responses and inputs are safely typed
105+
84106
## Features
85107
⚡️ Validates queries and selectors
86108
⚡️ Types mapped from your schema <br/>
@@ -124,6 +146,8 @@ For a complete guide to contributing to GraphQL Zeus, see the [Contribution Guid
124146
4. Push to the branch: git push origin my-new-feature
125147
5. Submit a pull request
126148
149+
150+
127151
## License
128152
129153
[MIT](https://opensource.org/licenses/MIT) 🕊

examples/typescript-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-node",
3-
"version": "3.0.4",
3+
"version": "3.0.5",
44
"description": "",
55
"private": true,
66
"main": "index.js",

examples/typescript-node/src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
$,
1414
FromSelector,
1515
fields,
16+
ComposableSelector,
1617
} from './zeus/index.js';
1718
import { typedGql } from './zeus/typedDocumentNode.js';
1819

@@ -109,7 +110,18 @@ const run = async () => {
109110
{ operationName: 'ZausCard' },
110111
);
111112
printQueryResult('ZeusCard', ZeusCard);
112-
113+
const withComposable = <T extends ComposableSelector<'Card'>, Z extends T>(id: string, rest: Z | T) =>
114+
Gql('query')({
115+
cardById: [{ cardId: id }, rest],
116+
});
117+
const c1result = await withComposable('12', {
118+
id: true,
119+
});
120+
const c2result = await withComposable('12', {
121+
Defense: true,
122+
Attack: true,
123+
});
124+
printQueryResult('composables', `1. ${c1result.cardById?.id} 2. ${c2result.cardById?.Attack}`);
113125
const bbb = await Gql('query')({
114126
drawCard: {
115127
...fields('Card'),

examples/typescript-node/src/zeus/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,8 @@ type OptionalKeys<T> = {
865865

866866
export type WithOptionalNullables<T> = OptionalKeys<WithNullableKeys<T>> & WithNonNullableKeys<T>;
867867

868+
export type ComposableSelector<T extends keyof ValueTypes> = ReturnType<SelectionFunction<ValueTypes[T]>>;
869+
868870
export type Variable<T extends GraphQLVariableType, Name extends string> = {
869871
' __zeus_name': Name;
870872
' __zeus_type': T;

packages/graphql-zeus-core/TreeToTS/functions/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,8 @@ type OptionalKeys<T> = {
824824
825825
export type WithOptionalNullables<T> = OptionalKeys<WithNullableKeys<T>> & WithNonNullableKeys<T>;
826826
827+
export type ComposableSelector<T extends keyof ValueTypes> = ReturnType<SelectionFunction<ValueTypes[T]>>;
828+
827829
export type Variable<T extends GraphQLVariableType, Name extends string> = {
828830
' __zeus_name': Name;
829831
' __zeus_type': T;

packages/graphql-zeus-core/TreeToTS/functions/new/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GraphQLTypes, ZEUS_VARIABLES, ZEUS_INTERFACES, ZEUS_UNIONS } from '@/TreeToTS/functions/new/mocks';
1+
import { GraphQLTypes, ZEUS_VARIABLES, ZEUS_INTERFACES, ZEUS_UNIONS, ValueTypes } from '@/TreeToTS/functions/new/mocks';
22
import { Variable } from '@/TreeToTS/functions/new/variableExtract';
33

44
export type UnwrapPromise<T> = T extends Promise<infer R> ? R : T;
@@ -148,3 +148,5 @@ type OptionalKeys<T> = {
148148
};
149149

150150
export type WithOptionalNullables<T> = OptionalKeys<WithNullableKeys<T>> & WithNonNullableKeys<T>;
151+
152+
export type ComposableSelector<T extends keyof ValueTypes> = ReturnType<SelectionFunction<ValueTypes[T]>>;

packages/graphql-zeus-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus-core",
3-
"version": "7.0.4",
3+
"version": "7.0.5",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "GraphQL Editor, Artur Czemiel",

packages/graphql-zeus-jsonschema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus-jsonschema",
3-
"version": "7.0.4",
3+
"version": "7.0.5",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "GraphQL Editor, Artur Czemiel",

packages/graphql-zeus/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-zeus",
3-
"version": "7.0.4",
3+
"version": "7.0.5",
44
"private": false,
55
"scripts": {
66
"start": "ttsc --watch",
@@ -26,8 +26,8 @@
2626
"dependencies": {
2727
"config-maker": "^0.0.6",
2828
"cross-fetch": "^3.0.4",
29-
"graphql-zeus-core": "^7.0.4",
30-
"graphql-zeus-jsonschema": "^7.0.4",
29+
"graphql-zeus-core": "^7.0.5",
30+
"graphql-zeus-jsonschema": "^7.0.5",
3131
"yargs": "^16.1.1"
3232
}
3333
}

0 commit comments

Comments
 (0)