Skip to content

Commit 6c0b654

Browse files
authored
Merge pull request #5 from Code-Hex/add/example
add example
2 parents d775b3c + 554fb89 commit 6c0b654

10 files changed

+181
-10
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
"ignorePatterns": [
3636
"dist",
3737
"node_modules",
38-
"gen"
38+
"example"
3939
]
4040
}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
node_modules
22
dist
33
.npmignore
4-
gen/*.ts
54
package-lock.json
65
.DS_Store
76
tsconfig.tsbuildinfo

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
dist
3+
.npmignore
4+
package-lock.json
5+
.DS_Store
6+
tsconfig.tsbuildinfo
7+
example

codegen.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
overwrite: true
2-
schema: './test.graphql'
2+
schema: './example/test.graphql'
33
generates:
4-
gen/types.ts:
4+
example/types.ts:
55
plugins:
66
- typescript
7-
gen/schemas.ts:
7+
example/yup/schemas.ts:
88
plugins:
99
- ./dist/main/index.js:
1010
schema: yup
11-
importFrom: ./types
11+
importFrom: ../types
1212
directives:
1313
required:
1414
msg: required
File renamed without changes.

example/types.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
export type Maybe<T> = T | null;
2+
export type InputMaybe<T> = Maybe<T>;
3+
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
4+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
5+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
6+
/** All built-in and custom scalars, mapped to their actual values */
7+
export type Scalars = {
8+
ID: string;
9+
String: string;
10+
Boolean: boolean;
11+
Int: number;
12+
Float: number;
13+
Date: any;
14+
URL: any;
15+
};
16+
17+
export type AttributeInput = {
18+
key?: InputMaybe<Scalars['String']>;
19+
val?: InputMaybe<Scalars['String']>;
20+
};
21+
22+
export enum ButtonComponentType {
23+
Button = 'BUTTON',
24+
Submit = 'SUBMIT'
25+
}
26+
27+
export type ComponentInput = {
28+
child?: InputMaybe<ComponentInput>;
29+
childrens?: InputMaybe<Array<InputMaybe<ComponentInput>>>;
30+
event?: InputMaybe<EventInput>;
31+
name: Scalars['String'];
32+
type: ButtonComponentType;
33+
};
34+
35+
export type DropDownComponentInput = {
36+
dropdownComponent?: InputMaybe<ComponentInput>;
37+
getEvent: EventInput;
38+
};
39+
40+
export type EventArgumentInput = {
41+
name: Scalars['String'];
42+
value: Scalars['String'];
43+
};
44+
45+
export type EventInput = {
46+
arguments: Array<EventArgumentInput>;
47+
options?: InputMaybe<Array<EventOptionType>>;
48+
};
49+
50+
export enum EventOptionType {
51+
Reload = 'RELOAD',
52+
Retry = 'RETRY'
53+
}
54+
55+
export type HttpInput = {
56+
method?: InputMaybe<HttpMethod>;
57+
url: Scalars['URL'];
58+
};
59+
60+
export enum HttpMethod {
61+
Get = 'GET',
62+
Post = 'POST'
63+
}
64+
65+
export type LayoutInput = {
66+
dropdown?: InputMaybe<DropDownComponentInput>;
67+
};
68+
69+
export type PageInput = {
70+
attributes?: InputMaybe<Array<AttributeInput>>;
71+
date?: InputMaybe<Scalars['Date']>;
72+
height: Scalars['Float'];
73+
id: Scalars['ID'];
74+
layout: LayoutInput;
75+
pageType: PageType;
76+
postIDs?: InputMaybe<Array<Scalars['ID']>>;
77+
show: Scalars['Boolean'];
78+
tags?: InputMaybe<Array<InputMaybe<Scalars['String']>>>;
79+
title: Scalars['String'];
80+
width: Scalars['Int'];
81+
};
82+
83+
export enum PageType {
84+
BasicAuth = 'BASIC_AUTH',
85+
Lp = 'LP',
86+
Restricted = 'RESTRICTED',
87+
Service = 'SERVICE'
88+
}

example/yup/schemas.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import * as yup from 'yup'
2+
import { AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, HttpInput, HttpMethod, LayoutInput, PageInput, PageType } from '../types'
3+
4+
export function AttributeInputSchema(): yup.SchemaOf<AttributeInput> {
5+
return yup.object({
6+
key: yup.string(),
7+
val: yup.string()
8+
})
9+
}
10+
11+
export const ButtonComponentTypeSchema = yup.mixed().oneOf([ButtonComponentType.Button, ButtonComponentType.Submit]);
12+
13+
export function ComponentInputSchema(): yup.SchemaOf<ComponentInput> {
14+
return yup.object({
15+
child: yup.lazy(() => ComponentInputSchema()) as never,
16+
childrens: yup.array().of(yup.lazy(() => ComponentInputSchema()) as never).optional(),
17+
event: yup.lazy(() => EventInputSchema()) as never,
18+
name: yup.string().defined(),
19+
type: ButtonComponentTypeSchema.defined()
20+
})
21+
}
22+
23+
export function DropDownComponentInputSchema(): yup.SchemaOf<DropDownComponentInput> {
24+
return yup.object({
25+
dropdownComponent: yup.lazy(() => ComponentInputSchema()) as never,
26+
getEvent: yup.lazy(() => EventInputSchema().defined()) as never
27+
})
28+
}
29+
30+
export function EventArgumentInputSchema(): yup.SchemaOf<EventArgumentInput> {
31+
return yup.object({
32+
name: yup.string().defined().min(5),
33+
value: yup.string().defined().matches(/^foo/)
34+
})
35+
}
36+
37+
export function EventInputSchema(): yup.SchemaOf<EventInput> {
38+
return yup.object({
39+
arguments: yup.array().of(yup.lazy(() => EventArgumentInputSchema().defined()) as never).defined(),
40+
options: yup.array().of(EventOptionTypeSchema.defined()).optional()
41+
})
42+
}
43+
44+
export const EventOptionTypeSchema = yup.mixed().oneOf([EventOptionType.Reload, EventOptionType.Retry]);
45+
46+
export function HttpInputSchema(): yup.SchemaOf<HttpInput> {
47+
return yup.object({
48+
method: HttpMethodSchema,
49+
url: yup.mixed().defined()
50+
})
51+
}
52+
53+
export const HttpMethodSchema = yup.mixed().oneOf([HttpMethod.Get, HttpMethod.Post]);
54+
55+
export function LayoutInputSchema(): yup.SchemaOf<LayoutInput> {
56+
return yup.object({
57+
dropdown: yup.lazy(() => DropDownComponentInputSchema()) as never
58+
})
59+
}
60+
61+
export function PageInputSchema(): yup.SchemaOf<PageInput> {
62+
return yup.object({
63+
attributes: yup.array().of(yup.lazy(() => AttributeInputSchema().defined()) as never).optional(),
64+
date: yup.mixed(),
65+
height: yup.number().defined(),
66+
id: yup.string().defined(),
67+
layout: yup.lazy(() => LayoutInputSchema().defined()) as never,
68+
pageType: PageTypeSchema.defined(),
69+
postIDs: yup.array().of(yup.string().defined()).optional(),
70+
show: yup.boolean().defined(),
71+
tags: yup.array().of(yup.string()).optional(),
72+
title: yup.string().defined(),
73+
width: yup.number().defined()
74+
})
75+
}
76+
77+
export const PageTypeSchema = yup.mixed().oneOf([PageType.BasicAuth, PageType.Lp, PageType.Restricted, PageType.Service]);

gen/.gitkeep

Whitespace-only changes.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"build:module": "tsc -p tsconfig.module.json",
2626
"lint": "eslint --ext .ts .",
2727
"lint-fix": "eslint --fix --ext .ts .",
28-
"prettier": "prettier --ignore-path .gitignore --write --list-different \"**/*.{ts,graphql,yml}\"",
29-
"prettier:check": "prettier --ignore-path .gitignore --check \"**/*.{ts,graphql,yml}\"",
28+
"prettier": "prettier --write --list-different \"**/*.{ts,graphql,yml}\"",
29+
"prettier:check": "prettier --check \"**/*.{ts,graphql,yml}\"",
3030
"generate": "run-p build:* && graphql-codegen",
3131
"prepublish": "run-p build:*"
3232
},

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"paths": {}
1111
},
1212
"include": [
13-
"src/*.ts"
13+
"src"
1414
],
1515
"exclude": [
16-
"./gen/*.ts",
16+
"./example",
1717
"./dist"
1818
]
1919
}

0 commit comments

Comments
 (0)