Skip to content

add example #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"ignorePatterns": [
"dist",
"node_modules",
"gen"
"example"
]
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules
dist
.npmignore
gen/*.ts
package-lock.json
.DS_Store
tsconfig.tsbuildinfo
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
dist
.npmignore
package-lock.json
.DS_Store
tsconfig.tsbuildinfo
example
8 changes: 4 additions & 4 deletions codegen.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
overwrite: true
schema: './test.graphql'
schema: './example/test.graphql'
generates:
gen/types.ts:
example/types.ts:
plugins:
- typescript
gen/schemas.ts:
example/yup/schemas.ts:
plugins:
- ./dist/main/index.js:
schema: yup
importFrom: ./types
importFrom: ../types
directives:
required:
msg: required
Expand Down
File renamed without changes.
88 changes: 88 additions & 0 deletions example/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
Date: any;
URL: any;
};

export type AttributeInput = {
key?: InputMaybe<Scalars['String']>;
val?: InputMaybe<Scalars['String']>;
};

export enum ButtonComponentType {
Button = 'BUTTON',
Submit = 'SUBMIT'
}

export type ComponentInput = {
child?: InputMaybe<ComponentInput>;
childrens?: InputMaybe<Array<InputMaybe<ComponentInput>>>;
event?: InputMaybe<EventInput>;
name: Scalars['String'];
type: ButtonComponentType;
};

export type DropDownComponentInput = {
dropdownComponent?: InputMaybe<ComponentInput>;
getEvent: EventInput;
};

export type EventArgumentInput = {
name: Scalars['String'];
value: Scalars['String'];
};

export type EventInput = {
arguments: Array<EventArgumentInput>;
options?: InputMaybe<Array<EventOptionType>>;
};

export enum EventOptionType {
Reload = 'RELOAD',
Retry = 'RETRY'
}

export type HttpInput = {
method?: InputMaybe<HttpMethod>;
url: Scalars['URL'];
};

export enum HttpMethod {
Get = 'GET',
Post = 'POST'
}

export type LayoutInput = {
dropdown?: InputMaybe<DropDownComponentInput>;
};

export type PageInput = {
attributes?: InputMaybe<Array<AttributeInput>>;
date?: InputMaybe<Scalars['Date']>;
height: Scalars['Float'];
id: Scalars['ID'];
layout: LayoutInput;
pageType: PageType;
postIDs?: InputMaybe<Array<Scalars['ID']>>;
show: Scalars['Boolean'];
tags?: InputMaybe<Array<InputMaybe<Scalars['String']>>>;
title: Scalars['String'];
width: Scalars['Int'];
};

export enum PageType {
BasicAuth = 'BASIC_AUTH',
Lp = 'LP',
Restricted = 'RESTRICTED',
Service = 'SERVICE'
}
77 changes: 77 additions & 0 deletions example/yup/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as yup from 'yup'
import { AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, HttpInput, HttpMethod, LayoutInput, PageInput, PageType } from '../types'

export function AttributeInputSchema(): yup.SchemaOf<AttributeInput> {
return yup.object({
key: yup.string(),
val: yup.string()
})
}

export const ButtonComponentTypeSchema = yup.mixed().oneOf([ButtonComponentType.Button, ButtonComponentType.Submit]);

export function ComponentInputSchema(): yup.SchemaOf<ComponentInput> {
return yup.object({
child: yup.lazy(() => ComponentInputSchema()) as never,
childrens: yup.array().of(yup.lazy(() => ComponentInputSchema()) as never).optional(),
event: yup.lazy(() => EventInputSchema()) as never,
name: yup.string().defined(),
type: ButtonComponentTypeSchema.defined()
})
}

export function DropDownComponentInputSchema(): yup.SchemaOf<DropDownComponentInput> {
return yup.object({
dropdownComponent: yup.lazy(() => ComponentInputSchema()) as never,
getEvent: yup.lazy(() => EventInputSchema().defined()) as never
})
}

export function EventArgumentInputSchema(): yup.SchemaOf<EventArgumentInput> {
return yup.object({
name: yup.string().defined().min(5),
value: yup.string().defined().matches(/^foo/)
})
}

export function EventInputSchema(): yup.SchemaOf<EventInput> {
return yup.object({
arguments: yup.array().of(yup.lazy(() => EventArgumentInputSchema().defined()) as never).defined(),
options: yup.array().of(EventOptionTypeSchema.defined()).optional()
})
}

export const EventOptionTypeSchema = yup.mixed().oneOf([EventOptionType.Reload, EventOptionType.Retry]);

export function HttpInputSchema(): yup.SchemaOf<HttpInput> {
return yup.object({
method: HttpMethodSchema,
url: yup.mixed().defined()
})
}

export const HttpMethodSchema = yup.mixed().oneOf([HttpMethod.Get, HttpMethod.Post]);

export function LayoutInputSchema(): yup.SchemaOf<LayoutInput> {
return yup.object({
dropdown: yup.lazy(() => DropDownComponentInputSchema()) as never
})
}

export function PageInputSchema(): yup.SchemaOf<PageInput> {
return yup.object({
attributes: yup.array().of(yup.lazy(() => AttributeInputSchema().defined()) as never).optional(),
date: yup.mixed(),
height: yup.number().defined(),
id: yup.string().defined(),
layout: yup.lazy(() => LayoutInputSchema().defined()) as never,
pageType: PageTypeSchema.defined(),
postIDs: yup.array().of(yup.string().defined()).optional(),
show: yup.boolean().defined(),
tags: yup.array().of(yup.string()).optional(),
title: yup.string().defined(),
width: yup.number().defined()
})
}

export const PageTypeSchema = yup.mixed().oneOf([PageType.BasicAuth, PageType.Lp, PageType.Restricted, PageType.Service]);
Empty file removed gen/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"build:module": "tsc -p tsconfig.module.json",
"lint": "eslint --ext .ts .",
"lint-fix": "eslint --fix --ext .ts .",
"prettier": "prettier --ignore-path .gitignore --write --list-different \"**/*.{ts,graphql,yml}\"",
"prettier:check": "prettier --ignore-path .gitignore --check \"**/*.{ts,graphql,yml}\"",
"prettier": "prettier --write --list-different \"**/*.{ts,graphql,yml}\"",
"prettier:check": "prettier --check \"**/*.{ts,graphql,yml}\"",
"generate": "run-p build:* && graphql-codegen",
"prepublish": "run-p build:*"
},
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"paths": {}
},
"include": [
"src/*.ts"
"src"
],
"exclude": [
"./gen/*.ts",
"./example",
"./dist"
]
}