From 972e8d3bf7c217fa700c5c27752b1222cdab77bd Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 24 Jan 2022 00:39:06 +0900 Subject: [PATCH 1/2] fixed to push example directory --- .eslintrc.json | 2 +- .gitignore | 1 - codegen.yml | 8 +-- test.graphql => example/test.graphql | 0 example/types.ts | 88 ++++++++++++++++++++++++++++ example/yup/schemas.ts | 77 ++++++++++++++++++++++++ gen/.gitkeep | 0 tsconfig.json | 4 +- 8 files changed, 172 insertions(+), 8 deletions(-) rename test.graphql => example/test.graphql (100%) create mode 100644 example/types.ts create mode 100644 example/yup/schemas.ts delete mode 100644 gen/.gitkeep diff --git a/.eslintrc.json b/.eslintrc.json index 0878234c..2691c5c5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -35,6 +35,6 @@ "ignorePatterns": [ "dist", "node_modules", - "gen" + "example" ] } \ No newline at end of file diff --git a/.gitignore b/.gitignore index f1d8060a..b5b67c3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ node_modules dist .npmignore -gen/*.ts package-lock.json .DS_Store tsconfig.tsbuildinfo \ No newline at end of file diff --git a/codegen.yml b/codegen.yml index af7c6a2a..1c24c845 100644 --- a/codegen.yml +++ b/codegen.yml @@ -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 diff --git a/test.graphql b/example/test.graphql similarity index 100% rename from test.graphql rename to example/test.graphql diff --git a/example/types.ts b/example/types.ts new file mode 100644 index 00000000..62283b3c --- /dev/null +++ b/example/types.ts @@ -0,0 +1,88 @@ +export type Maybe = T | null; +export type InputMaybe = Maybe; +export type Exact = { [K in keyof T]: T[K] }; +export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; +/** 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; + val?: InputMaybe; +}; + +export enum ButtonComponentType { + Button = 'BUTTON', + Submit = 'SUBMIT' +} + +export type ComponentInput = { + child?: InputMaybe; + childrens?: InputMaybe>>; + event?: InputMaybe; + name: Scalars['String']; + type: ButtonComponentType; +}; + +export type DropDownComponentInput = { + dropdownComponent?: InputMaybe; + getEvent: EventInput; +}; + +export type EventArgumentInput = { + name: Scalars['String']; + value: Scalars['String']; +}; + +export type EventInput = { + arguments: Array; + options?: InputMaybe>; +}; + +export enum EventOptionType { + Reload = 'RELOAD', + Retry = 'RETRY' +} + +export type HttpInput = { + method?: InputMaybe; + url: Scalars['URL']; +}; + +export enum HttpMethod { + Get = 'GET', + Post = 'POST' +} + +export type LayoutInput = { + dropdown?: InputMaybe; +}; + +export type PageInput = { + attributes?: InputMaybe>; + date?: InputMaybe; + height: Scalars['Float']; + id: Scalars['ID']; + layout: LayoutInput; + pageType: PageType; + postIDs?: InputMaybe>; + show: Scalars['Boolean']; + tags?: InputMaybe>>; + title: Scalars['String']; + width: Scalars['Int']; +}; + +export enum PageType { + BasicAuth = 'BASIC_AUTH', + Lp = 'LP', + Restricted = 'RESTRICTED', + Service = 'SERVICE' +} diff --git a/example/yup/schemas.ts b/example/yup/schemas.ts new file mode 100644 index 00000000..f77b3545 --- /dev/null +++ b/example/yup/schemas.ts @@ -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 { + return yup.object({ + key: yup.string(), + val: yup.string() + }) +} + +export const ButtonComponentTypeSchema = yup.mixed().oneOf([ButtonComponentType.Button, ButtonComponentType.Submit]); + +export function ComponentInputSchema(): yup.SchemaOf { + 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 { + return yup.object({ + dropdownComponent: yup.lazy(() => ComponentInputSchema()) as never, + getEvent: yup.lazy(() => EventInputSchema().defined()) as never + }) +} + +export function EventArgumentInputSchema(): yup.SchemaOf { + return yup.object({ + name: yup.string().defined().min(5), + value: yup.string().defined().matches(/^foo/) + }) +} + +export function EventInputSchema(): yup.SchemaOf { + 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 { + return yup.object({ + method: HttpMethodSchema, + url: yup.mixed().defined() + }) +} + +export const HttpMethodSchema = yup.mixed().oneOf([HttpMethod.Get, HttpMethod.Post]); + +export function LayoutInputSchema(): yup.SchemaOf { + return yup.object({ + dropdown: yup.lazy(() => DropDownComponentInputSchema()) as never + }) +} + +export function PageInputSchema(): yup.SchemaOf { + 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]); diff --git a/gen/.gitkeep b/gen/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/tsconfig.json b/tsconfig.json index ecb0cb28..dd41427a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,10 +10,10 @@ "paths": {} }, "include": [ - "src/*.ts" + "src" ], "exclude": [ - "./gen/*.ts", + "./example", "./dist" ] } \ No newline at end of file From 554fb89d392cace54c123ccd5dc4a2c0cac51ce0 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 24 Jan 2022 00:44:37 +0900 Subject: [PATCH 2/2] added .prettierignore --- .prettierignore | 7 +++++++ package.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..16fa69f8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +node_modules +dist +.npmignore +package-lock.json +.DS_Store +tsconfig.tsbuildinfo +example diff --git a/package.json b/package.json index 02f71900..6c1496b3 100644 --- a/package.json +++ b/package.json @@ -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:*" },