From 6a85e0bd6ffd3f0d08df6186c2aa6333aed8f1a5 Mon Sep 17 00:00:00 2001 From: Ville Saukkonen Date: Mon, 14 Feb 2022 00:59:42 +0200 Subject: [PATCH 1/4] allow passing schema plugins --- __tests__/__fixtures/tsconfig/graphql-let.yml | 2 + .../__fixtures/tsconfig/graphql-let2.yml | 2 + .../__fixtures/tsconfig/graphql-let3.yml | 2 + .../__fixtures/tsconfig/graphql-let4.yml | 2 + __tests__/__snapshots__/babel.ts.snap | 1304 ----------------- package.json | 1 + src/__fixtures/loader/basic/.graphql-let.yml | 2 + src/__snapshots__/loader.test.ts.snap | 182 ++- .../graphql-codegen/.graphql-let.yml | 2 + src/lib/__snapshots__/codegen.test.ts.snap | 38 +- src/lib/__snapshots__/config.test.ts.snap | 2 + src/lib/codegen.ts | 8 +- src/lib/config.ts | 2 + yarn.lock | 476 ++++++ 14 files changed, 695 insertions(+), 1330 deletions(-) delete mode 100644 __tests__/__snapshots__/babel.ts.snap diff --git a/__tests__/__fixtures/tsconfig/graphql-let.yml b/__tests__/__fixtures/tsconfig/graphql-let.yml index 6e45326d..57012e77 100644 --- a/__tests__/__fixtures/tsconfig/graphql-let.yml +++ b/__tests__/__fixtures/tsconfig/graphql-let.yml @@ -4,6 +4,8 @@ documents: plugins: - typescript-operations - typescript-react-apollo +schemaPlugins: + - typescript-urql-graphcache config: useIndexSignature: true TSConfigFile: es3config.json diff --git a/__tests__/__fixtures/tsconfig/graphql-let2.yml b/__tests__/__fixtures/tsconfig/graphql-let2.yml index b926f111..adf126db 100644 --- a/__tests__/__fixtures/tsconfig/graphql-let2.yml +++ b/__tests__/__fixtures/tsconfig/graphql-let2.yml @@ -4,6 +4,8 @@ documents: plugins: - typescript-operations - typescript-react-apollo +schemaPlugins: + - typescript-urql-graphcache config: withHOC: false withHocks: true diff --git a/__tests__/__fixtures/tsconfig/graphql-let3.yml b/__tests__/__fixtures/tsconfig/graphql-let3.yml index e25f9424..32155b29 100644 --- a/__tests__/__fixtures/tsconfig/graphql-let3.yml +++ b/__tests__/__fixtures/tsconfig/graphql-let3.yml @@ -4,6 +4,8 @@ documents: plugins: - typescript-operations - typescript-react-apollo +schemaPlugins: + - typescript-urql-graphcache config: useIndexSignature: true cacheDir: .cache diff --git a/__tests__/__fixtures/tsconfig/graphql-let4.yml b/__tests__/__fixtures/tsconfig/graphql-let4.yml index 2625a115..e1852e98 100644 --- a/__tests__/__fixtures/tsconfig/graphql-let4.yml +++ b/__tests__/__fixtures/tsconfig/graphql-let4.yml @@ -7,6 +7,8 @@ documents: plugins: - typescript-operations - typescript-react-apollo +schemaPlugins: + - typescript-urql-graphcache config: useIndexSignature: true cacheDir: .cache diff --git a/__tests__/__snapshots__/babel.ts.snap b/__tests__/__snapshots__/babel.ts.snap deleted file mode 100644 index 39adb3d8..00000000 --- a/__tests__/__snapshots__/babel.ts.snap +++ /dev/null @@ -1,1304 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`graphql-let macro-gql: **/node_modules/** 1`] = ` -Array [ - node_modules/.cache/graphql-let/__types__.tsx, - node_modules/.cache/graphql-let/input-Viewer-Partial.ts, - node_modules/@types/graphql-let/__generated__/__types__.d.ts, - node_modules/@types/graphql-let/__generated__/input-Viewer-Partial.d.ts, - node_modules/@types/graphql-let/index.d.ts, - node_modules/@types/graphql-let/macro.d.ts, -] -`; - -exports[`graphql-let macro-gql: macro-gql 1`] = ` - -import { gql } from 'graphql-let/macro'; - -const { useViewerQuery } = gql(\` - # import Partial from './documents/partial.graphql' - query Viewer { - viewer { - ...Partial - } - } -\`); - -function nest1() { - function nest2() { - function nest3() { - function nest4() { - function MyComponent() { - useViewerQuery().data.viewer.name as string; - // @ts-expect-error - useViewerQuery() as number; - } - } - } - } -} - - ↓ ↓ ↓ ↓ ↓ ↓ - -import * as Ved68302f0b7c4c812ed026e4ca84e5c30072a6ca from './node_modules/.cache/graphql-let/input-Viewer-Partial.ts'; -const { useViewerQuery } = Ved68302f0b7c4c812ed026e4ca84e5c30072a6ca; - -function nest1() { - function nest2() { - function nest3() { - function nest4() { - function MyComponent() { - useViewerQuery().data.viewer.name; // @ts-expect-error - - useViewerQuery(); - } - } - } - } -} - - -`; - -exports[`graphql-let macro-gql: node_modules/.cache/graphql-let/__types__.tsx 1`] = ` -/* 497fd3cc5b4adebcf3aada3a62576980d87716cf - * This file is automatically generated by graphql-let. */ - -import { GraphQLResolveInfo } from 'graphql'; -export type Maybe = T | null; -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; -}; - -export type Query = { - __typename?: 'Query'; - viewer?: Maybe; -}; - -export type User = { - __typename?: 'User'; - id: Scalars['ID']; - name: Scalars['String']; - status: Scalars['String']; -}; - -export type WithIndex = TObject & Record; -export type ResolversObject = WithIndex; - -export type ResolverTypeWrapper = Promise | T; - - -export type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; - -export type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export type Resolver = - | ResolverFn - | StitchingResolver; - -export type ResolverFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => Promise | TResult; - -export type SubscriptionSubscribeFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => AsyncIterator | Promise>; - -export type SubscriptionResolveFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} - -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} - -export type SubscriptionObject = - | SubscriptionSubscriberObject - | SubscriptionResolverObject; - -export type SubscriptionResolver = - | ((...args: any[]) => SubscriptionObject) - | SubscriptionObject; - -export type TypeResolveFn = ( - parent: TParent, - context: TContext, - info: GraphQLResolveInfo -) => Maybe | Promise>; - -export type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; - -export type NextResolverFn = () => Promise; - -export type DirectiveResolverFn = ( - next: NextResolverFn, - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -/** Mapping between all available schema types and the resolvers types */ -export type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; - -/** Mapping between all available schema types and the resolvers parents */ -export type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; - -export type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; - -export type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; - -export type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; - - -/** - * @deprecated - * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. - */ -export type IResolvers = Resolvers; - -`; - -exports[`graphql-let macro-gql: node_modules/.cache/graphql-let/input-Viewer-Partial.ts 1`] = ` -/* ed68302f0b7c4c812ed026e4ca84e5c30072a6ca - * This file is automatically generated by graphql-let. */ - -import * as Types from './__types__'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} -export type ViewerQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type ViewerQuery = ( - { __typename?: 'Query' } - & { viewer?: Types.Maybe<( - { __typename?: 'User' } - & PartialFragment - )> } -); - -export type PartialFragment = ( - { __typename?: 'User' } - & Pick -); - -export const PartialFragmentDoc = gql\` - fragment Partial on User { - id - name - status -} - \`; -export const ViewerDocument = gql\` - query Viewer { - viewer { - ...Partial - } -} - \${PartialFragmentDoc}\`; - -/** - * __useViewerQuery__ - * - * To run a query within a React component, call \`useViewerQuery\` and pass it any options that fit your needs. - * When your component renders, \`useViewerQuery\` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useViewerQuery({ - * variables: { - * }, - * }); - */ -export function useViewerQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(ViewerDocument, options); - } -export function useViewerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(ViewerDocument, options); - } -export type ViewerQueryHookResult = ReturnType; -export type ViewerLazyQueryHookResult = ReturnType; -export type ViewerQueryResult = Apollo.QueryResult; -`; - -exports[`graphql-let macro-gql: node_modules/@types/graphql-let/__generated__/__types__.d.ts 1`] = ` -/* 497fd3cc5b4adebcf3aada3a62576980d87716cf - * This file is automatically generated by graphql-let. */ - -import { GraphQLResolveInfo } from 'graphql'; -export declare type Maybe = T | null; -export declare type Exact = { [K in keyof T]: T[K] }; -export declare type MakeOptional = Omit & { [SubKey in K]?: Maybe }; -export declare type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -/** All built-in and custom scalars, mapped to their actual values */ - -export declare type Scalars = { - ID: string; - String: string; - Boolean: boolean; - Int: number; - Float: number; -}; -export declare type Query = { - __typename?: 'Query'; - viewer?: Maybe; -}; -export declare type User = { - __typename?: 'User'; - id: Scalars['ID']; - name: Scalars['String']; - status: Scalars['String']; -}; -export declare type WithIndex = TObject & Record; -export declare type ResolversObject = WithIndex; -export declare type ResolverTypeWrapper = Promise | T; -export declare type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; -export declare type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export declare type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export declare type Resolver = ResolverFn | StitchingResolver; -export declare type ResolverFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise | TResult; -export declare type SubscriptionSubscribeFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => AsyncIterator | Promise>; -export declare type SubscriptionResolveFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise; -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} -export declare type SubscriptionObject = SubscriptionSubscriberObject | SubscriptionResolverObject; -export declare type SubscriptionResolver = ((...args: any[]) => SubscriptionObject) | SubscriptionObject; -export declare type TypeResolveFn = (parent: TParent, context: TContext, info: GraphQLResolveInfo) => Maybe | Promise>; -export declare type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; -export declare type NextResolverFn = () => Promise; -export declare type DirectiveResolverFn = (next: NextResolverFn, parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise; -/** Mapping between all available schema types and the resolvers types */ - -export declare type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; -/** Mapping between all available schema types and the resolvers parents */ - -export declare type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; -export declare type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; -export declare type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; -export declare type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; -/** - * @deprecated - * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. - */ - -export declare type IResolvers = Resolvers; -`; - -exports[`graphql-let macro-gql: node_modules/@types/graphql-let/__generated__/input-Viewer-Partial.d.ts 1`] = ` -/* ed68302f0b7c4c812ed026e4ca84e5c30072a6ca - * This file is automatically generated by graphql-let. */ - -import * as Types from "./__types__"; -import * as Apollo from '@apollo/client'; -export declare type ViewerQueryVariables = Types.Exact<{ - [key: string]: never; -}>; -export declare type ViewerQuery = ({ - __typename?: 'Query'; -} & { - viewer?: Types.Maybe<({ - __typename?: 'User'; - } & PartialFragment)>; -}); -export declare type PartialFragment = ({ - __typename?: 'User'; -} & Pick); -export declare const PartialFragmentDoc: Apollo.DocumentNode; -export declare const ViewerDocument: Apollo.DocumentNode; -/** - * __useViewerQuery__ - * - * To run a query within a React component, call \`useViewerQuery\` and pass it any options that fit your needs. - * When your component renders, \`useViewerQuery\` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useViewerQuery({ - * variables: { - * }, - * }); - */ - -export declare function useViewerQuery(baseOptions?: Apollo.QueryHookOptions): Apollo.QueryResult>; -export declare function useViewerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions): Apollo.QueryTuple>; -export declare type ViewerQueryHookResult = ReturnType; -export declare type ViewerLazyQueryHookResult = ReturnType; -export declare type ViewerQueryResult = Apollo.QueryResult; -export declare type __GraphQLLetTypeInjection = { - PartialFragmentDoc: typeof PartialFragmentDoc; - ViewerDocument: typeof ViewerDocument; - useViewerQuery: typeof useViewerQuery; - useViewerLazyQuery: typeof useViewerLazyQuery; -}; -`; - -exports[`graphql-let macro-gql: node_modules/@types/graphql-let/index.d.ts 1`] = ` -import Ted68302f0b7c4c812ed026e4ca84e5c30072a6ca from './__generated__/input-Viewer-Partial'; -export function gql(gql: \` - # import Partial from './documents/partial.graphql' - query Viewer { - viewer { - ...Partial - } - } -\`): Ted68302f0b7c4c812ed026e4ca84e5c30072a6ca.__GraphQLLetTypeInjection; - -`; - -exports[`graphql-let macro-gql: node_modules/@types/graphql-let/macro.d.ts 1`] = ` -export { gql } from "."; - -`; - -exports[`graphql-let macro-load: **/node_modules/** 1`] = ` -Array [ - node_modules/.cache/graphql-let/__types__.tsx, - node_modules/.cache/graphql-let/input-Viewer-Partial.ts, - node_modules/@types/graphql-let/__generated__/__types__.d.ts, - node_modules/@types/graphql-let/__generated__/input-Viewer-Partial.d.ts, - node_modules/@types/graphql-let/index.d.ts, - node_modules/@types/graphql-let/macro.d.ts, -] -`; - -exports[`graphql-let macro-load: macro-load 1`] = ` - -import { load } from 'graphql-let/macro'; - -const { useViewerQuery } = load(\`./documents/viewer.graphql\`); - -function nest1() { - function nest2() { - function nest3() { - function nest4() { - function MyComponent() { - useViewerQuery().data.viewer.name as string; - // @ts-expect-error - useViewerQuery() as number; - } - } - } - } -} - - ↓ ↓ ↓ ↓ ↓ ↓ - -import * as V479e1b051ff6ed35fa952ede1d8cda20a5b8d114 from './node_modules/.cache/graphql-let/input-Viewer-Partial.ts'; -const { useViewerQuery } = V479e1b051ff6ed35fa952ede1d8cda20a5b8d114; - -function nest1() { - function nest2() { - function nest3() { - function nest4() { - function MyComponent() { - useViewerQuery().data.viewer.name; // @ts-expect-error - - useViewerQuery(); - } - } - } - } -} - - -`; - -exports[`graphql-let macro-load: node_modules/.cache/graphql-let/__types__.tsx 1`] = ` -/* 497fd3cc5b4adebcf3aada3a62576980d87716cf - * This file is automatically generated by graphql-let. */ - -import { GraphQLResolveInfo } from 'graphql'; -export type Maybe = T | null; -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; -}; - -export type Query = { - __typename?: 'Query'; - viewer?: Maybe; -}; - -export type User = { - __typename?: 'User'; - id: Scalars['ID']; - name: Scalars['String']; - status: Scalars['String']; -}; - -export type WithIndex = TObject & Record; -export type ResolversObject = WithIndex; - -export type ResolverTypeWrapper = Promise | T; - - -export type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; - -export type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export type Resolver = - | ResolverFn - | StitchingResolver; - -export type ResolverFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => Promise | TResult; - -export type SubscriptionSubscribeFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => AsyncIterator | Promise>; - -export type SubscriptionResolveFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} - -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} - -export type SubscriptionObject = - | SubscriptionSubscriberObject - | SubscriptionResolverObject; - -export type SubscriptionResolver = - | ((...args: any[]) => SubscriptionObject) - | SubscriptionObject; - -export type TypeResolveFn = ( - parent: TParent, - context: TContext, - info: GraphQLResolveInfo -) => Maybe | Promise>; - -export type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; - -export type NextResolverFn = () => Promise; - -export type DirectiveResolverFn = ( - next: NextResolverFn, - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -/** Mapping between all available schema types and the resolvers types */ -export type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; - -/** Mapping between all available schema types and the resolvers parents */ -export type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; - -export type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; - -export type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; - -export type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; - - -/** - * @deprecated - * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. - */ -export type IResolvers = Resolvers; - -`; - -exports[`graphql-let macro-load: node_modules/.cache/graphql-let/input-Viewer-Partial.ts 1`] = ` -/* 479e1b051ff6ed35fa952ede1d8cda20a5b8d114 - * This file is automatically generated by graphql-let. */ - -import * as Types from './__types__'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} -export type ViewerQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type ViewerQuery = ( - { __typename?: 'Query' } - & { viewer?: Types.Maybe<( - { __typename?: 'User' } - & PartialFragment - )> } -); - -export type PartialFragment = ( - { __typename?: 'User' } - & Pick -); - -export const PartialFragmentDoc = gql\` - fragment Partial on User { - id - name - status -} - \`; -export const ViewerDocument = gql\` - query Viewer { - viewer { - ...Partial - } -} - \${PartialFragmentDoc}\`; - -/** - * __useViewerQuery__ - * - * To run a query within a React component, call \`useViewerQuery\` and pass it any options that fit your needs. - * When your component renders, \`useViewerQuery\` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useViewerQuery({ - * variables: { - * }, - * }); - */ -export function useViewerQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(ViewerDocument, options); - } -export function useViewerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(ViewerDocument, options); - } -export type ViewerQueryHookResult = ReturnType; -export type ViewerLazyQueryHookResult = ReturnType; -export type ViewerQueryResult = Apollo.QueryResult; -`; - -exports[`graphql-let macro-load: node_modules/@types/graphql-let/__generated__/__types__.d.ts 1`] = ` -/* 497fd3cc5b4adebcf3aada3a62576980d87716cf - * This file is automatically generated by graphql-let. */ - -import { GraphQLResolveInfo } from 'graphql'; -export declare type Maybe = T | null; -export declare type Exact = { [K in keyof T]: T[K] }; -export declare type MakeOptional = Omit & { [SubKey in K]?: Maybe }; -export declare type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -/** All built-in and custom scalars, mapped to their actual values */ - -export declare type Scalars = { - ID: string; - String: string; - Boolean: boolean; - Int: number; - Float: number; -}; -export declare type Query = { - __typename?: 'Query'; - viewer?: Maybe; -}; -export declare type User = { - __typename?: 'User'; - id: Scalars['ID']; - name: Scalars['String']; - status: Scalars['String']; -}; -export declare type WithIndex = TObject & Record; -export declare type ResolversObject = WithIndex; -export declare type ResolverTypeWrapper = Promise | T; -export declare type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; -export declare type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export declare type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export declare type Resolver = ResolverFn | StitchingResolver; -export declare type ResolverFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise | TResult; -export declare type SubscriptionSubscribeFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => AsyncIterator | Promise>; -export declare type SubscriptionResolveFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise; -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} -export declare type SubscriptionObject = SubscriptionSubscriberObject | SubscriptionResolverObject; -export declare type SubscriptionResolver = ((...args: any[]) => SubscriptionObject) | SubscriptionObject; -export declare type TypeResolveFn = (parent: TParent, context: TContext, info: GraphQLResolveInfo) => Maybe | Promise>; -export declare type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; -export declare type NextResolverFn = () => Promise; -export declare type DirectiveResolverFn = (next: NextResolverFn, parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise; -/** Mapping between all available schema types and the resolvers types */ - -export declare type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; -/** Mapping between all available schema types and the resolvers parents */ - -export declare type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; -export declare type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; -export declare type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; -export declare type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; -/** - * @deprecated - * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. - */ - -export declare type IResolvers = Resolvers; -`; - -exports[`graphql-let macro-load: node_modules/@types/graphql-let/__generated__/input-Viewer-Partial.d.ts 1`] = ` -/* 479e1b051ff6ed35fa952ede1d8cda20a5b8d114 - * This file is automatically generated by graphql-let. */ - -import * as Types from "./__types__"; -import * as Apollo from '@apollo/client'; -export declare type ViewerQueryVariables = Types.Exact<{ - [key: string]: never; -}>; -export declare type ViewerQuery = ({ - __typename?: 'Query'; -} & { - viewer?: Types.Maybe<({ - __typename?: 'User'; - } & PartialFragment)>; -}); -export declare type PartialFragment = ({ - __typename?: 'User'; -} & Pick); -export declare const PartialFragmentDoc: Apollo.DocumentNode; -export declare const ViewerDocument: Apollo.DocumentNode; -/** - * __useViewerQuery__ - * - * To run a query within a React component, call \`useViewerQuery\` and pass it any options that fit your needs. - * When your component renders, \`useViewerQuery\` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useViewerQuery({ - * variables: { - * }, - * }); - */ - -export declare function useViewerQuery(baseOptions?: Apollo.QueryHookOptions): Apollo.QueryResult>; -export declare function useViewerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions): Apollo.QueryTuple>; -export declare type ViewerQueryHookResult = ReturnType; -export declare type ViewerLazyQueryHookResult = ReturnType; -export declare type ViewerQueryResult = Apollo.QueryResult; -export declare type __GraphQLLetTypeInjection = { - PartialFragmentDoc: typeof PartialFragmentDoc; - ViewerDocument: typeof ViewerDocument; - useViewerQuery: typeof useViewerQuery; - useViewerLazyQuery: typeof useViewerLazyQuery; -}; -`; - -exports[`graphql-let macro-load: node_modules/@types/graphql-let/index.d.ts 1`] = ` -import T479e1b051ff6ed35fa952ede1d8cda20a5b8d114 from './__generated__/input-Viewer-Partial'; -export function load(load: \`./documents/viewer.graphql\`): T479e1b051ff6ed35fa952ede1d8cda20a5b8d114.__GraphQLLetTypeInjection; - -`; - -exports[`graphql-let macro-load: node_modules/@types/graphql-let/macro.d.ts 1`] = ` -export { load } from "."; - -`; - -exports[`graphql-let plugin: **/node_modules/** 1`] = ` -Array [ - node_modules/.cache/graphql-let/__types__.tsx, - node_modules/.cache/graphql-let/input-Viewer.ts, - node_modules/@types/graphql-let/__generated__/__types__.d.ts, - node_modules/@types/graphql-let/__generated__/input-Viewer.d.ts, - node_modules/@types/graphql-let/index.d.ts, - node_modules/@types/graphql-let/macro.d.ts, -] -`; - -exports[`graphql-let plugin: node_modules/.cache/graphql-let/__types__.tsx 1`] = ` -/* 497fd3cc5b4adebcf3aada3a62576980d87716cf - * This file is automatically generated by graphql-let. */ - -import { GraphQLResolveInfo } from 'graphql'; -export type Maybe = T | null; -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; -}; - -export type Query = { - __typename?: 'Query'; - viewer?: Maybe; -}; - -export type User = { - __typename?: 'User'; - id: Scalars['ID']; - name: Scalars['String']; - status: Scalars['String']; -}; - -export type WithIndex = TObject & Record; -export type ResolversObject = WithIndex; - -export type ResolverTypeWrapper = Promise | T; - - -export type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; - -export type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export type Resolver = - | ResolverFn - | StitchingResolver; - -export type ResolverFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => Promise | TResult; - -export type SubscriptionSubscribeFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => AsyncIterator | Promise>; - -export type SubscriptionResolveFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} - -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} - -export type SubscriptionObject = - | SubscriptionSubscriberObject - | SubscriptionResolverObject; - -export type SubscriptionResolver = - | ((...args: any[]) => SubscriptionObject) - | SubscriptionObject; - -export type TypeResolveFn = ( - parent: TParent, - context: TContext, - info: GraphQLResolveInfo -) => Maybe | Promise>; - -export type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; - -export type NextResolverFn = () => Promise; - -export type DirectiveResolverFn = ( - next: NextResolverFn, - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -/** Mapping between all available schema types and the resolvers types */ -export type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; - -/** Mapping between all available schema types and the resolvers parents */ -export type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; - -export type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; - -export type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; - -export type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; - - -/** - * @deprecated - * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. - */ -export type IResolvers = Resolvers; - -`; - -exports[`graphql-let plugin: node_modules/.cache/graphql-let/input-Viewer.ts 1`] = ` -/* af49db201f15491f76f205723da63c0469e1a52e - * This file is automatically generated by graphql-let. */ - -import * as Types from './__types__'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} -export type ViewerQueryVariables = Types.Exact<{ [key: string]: never; }>; - - -export type ViewerQuery = ( - { __typename?: 'Query' } - & { viewer?: Types.Maybe<( - { __typename?: 'User' } - & Pick - )> } -); - - -export const ViewerDocument = gql\` - query Viewer { - viewer { - name - } -} - \`; - -/** - * __useViewerQuery__ - * - * To run a query within a React component, call \`useViewerQuery\` and pass it any options that fit your needs. - * When your component renders, \`useViewerQuery\` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useViewerQuery({ - * variables: { - * }, - * }); - */ -export function useViewerQuery(baseOptions?: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(ViewerDocument, options); - } -export function useViewerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(ViewerDocument, options); - } -export type ViewerQueryHookResult = ReturnType; -export type ViewerLazyQueryHookResult = ReturnType; -export type ViewerQueryResult = Apollo.QueryResult; -`; - -exports[`graphql-let plugin: node_modules/@types/graphql-let/__generated__/__types__.d.ts 1`] = ` -/* 497fd3cc5b4adebcf3aada3a62576980d87716cf - * This file is automatically generated by graphql-let. */ - -import { GraphQLResolveInfo } from 'graphql'; -export declare type Maybe = T | null; -export declare type Exact = { [K in keyof T]: T[K] }; -export declare type MakeOptional = Omit & { [SubKey in K]?: Maybe }; -export declare type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -/** All built-in and custom scalars, mapped to their actual values */ - -export declare type Scalars = { - ID: string; - String: string; - Boolean: boolean; - Int: number; - Float: number; -}; -export declare type Query = { - __typename?: 'Query'; - viewer?: Maybe; -}; -export declare type User = { - __typename?: 'User'; - id: Scalars['ID']; - name: Scalars['String']; - status: Scalars['String']; -}; -export declare type WithIndex = TObject & Record; -export declare type ResolversObject = WithIndex; -export declare type ResolverTypeWrapper = Promise | T; -export declare type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; -export declare type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export declare type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export declare type Resolver = ResolverFn | StitchingResolver; -export declare type ResolverFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise | TResult; -export declare type SubscriptionSubscribeFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => AsyncIterator | Promise>; -export declare type SubscriptionResolveFn = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise; -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} -export declare type SubscriptionObject = SubscriptionSubscriberObject | SubscriptionResolverObject; -export declare type SubscriptionResolver = ((...args: any[]) => SubscriptionObject) | SubscriptionObject; -export declare type TypeResolveFn = (parent: TParent, context: TContext, info: GraphQLResolveInfo) => Maybe | Promise>; -export declare type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; -export declare type NextResolverFn = () => Promise; -export declare type DirectiveResolverFn = (next: NextResolverFn, parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise; -/** Mapping between all available schema types and the resolvers types */ - -export declare type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; -/** Mapping between all available schema types and the resolvers parents */ - -export declare type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; -export declare type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; -export declare type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; -export declare type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; -/** - * @deprecated - * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. - */ - -export declare type IResolvers = Resolvers; -`; - -exports[`graphql-let plugin: node_modules/@types/graphql-let/__generated__/input-Viewer.d.ts 1`] = ` -/* af49db201f15491f76f205723da63c0469e1a52e - * This file is automatically generated by graphql-let. */ - -import * as Types from "./__types__"; -import * as Apollo from '@apollo/client'; -export declare type ViewerQueryVariables = Types.Exact<{ - [key: string]: never; -}>; -export declare type ViewerQuery = ({ - __typename?: 'Query'; -} & { - viewer?: Types.Maybe<({ - __typename?: 'User'; - } & Pick)>; -}); -export declare const ViewerDocument: Apollo.DocumentNode; -/** - * __useViewerQuery__ - * - * To run a query within a React component, call \`useViewerQuery\` and pass it any options that fit your needs. - * When your component renders, \`useViewerQuery\` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useViewerQuery({ - * variables: { - * }, - * }); - */ - -export declare function useViewerQuery(baseOptions?: Apollo.QueryHookOptions): Apollo.QueryResult>; -export declare function useViewerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions): Apollo.QueryTuple>; -export declare type ViewerQueryHookResult = ReturnType; -export declare type ViewerLazyQueryHookResult = ReturnType; -export declare type ViewerQueryResult = Apollo.QueryResult; -export declare type __GraphQLLetTypeInjection = { - ViewerDocument: typeof ViewerDocument; - useViewerQuery: typeof useViewerQuery; - useViewerLazyQuery: typeof useViewerLazyQuery; -}; -`; - -exports[`graphql-let plugin: node_modules/@types/graphql-let/index.d.ts 1`] = ` -import Taf49db201f15491f76f205723da63c0469e1a52e from './__generated__/input-Viewer'; -export function gql(gql: \`query Viewer { viewer { name } }\`): Taf49db201f15491f76f205723da63c0469e1a52e.__GraphQLLetTypeInjection; - -`; - -exports[`graphql-let plugin: node_modules/@types/graphql-let/macro.d.ts 1`] = ` -export { gql } from "."; - -`; - -exports[`graphql-let plugin: plugin 1`] = ` - -import { gql } from 'graphql-let'; - -const { useViewerQuery } = gql(\`query Viewer { viewer { name } }\`); - -function nest1() { - function nest2() { - function nest3() { - function nest4() { - function MyComponent() { - useViewerQuery().data.viewer.name as string; - // @ts-expect-error - useViewerQuery() as number; - } - } - } - } -} - - ↓ ↓ ↓ ↓ ↓ ↓ - -import * as Vaf49db201f15491f76f205723da63c0469e1a52e from './node_modules/.cache/graphql-let/input-Viewer.ts'; -const { useViewerQuery } = Vaf49db201f15491f76f205723da63c0469e1a52e; - -function nest1() { - function nest2() { - function nest3() { - function nest4() { - function MyComponent() { - useViewerQuery().data.viewer.name; // @ts-expect-error - - useViewerQuery(); - } - } - } - } -} - - -`; diff --git a/package.json b/package.json index b1024d06..41b4de53 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@graphql-codegen/typescript-operations": "1.18.4", "@graphql-codegen/typescript-react-apollo": "2.3.1", "@graphql-codegen/typescript-resolvers": "1.19.1", + "@graphql-codegen/typescript-urql-graphcache": "^2.2.4", "@graphql-tools/graphql-file-loader": "6.2.7", "@graphql-tools/import": "6.4.0", "@jest/transform": "27.2.0", diff --git a/src/__fixtures/loader/basic/.graphql-let.yml b/src/__fixtures/loader/basic/.graphql-let.yml index 586020a5..5e575fc0 100644 --- a/src/__fixtures/loader/basic/.graphql-let.yml +++ b/src/__fixtures/loader/basic/.graphql-let.yml @@ -5,5 +5,7 @@ documents: plugins: - typescript-operations - typescript-react-apollo +schemaPlugins: + - typescript-urql-graphcache respectGitIgnore: true cacheDir: .cache diff --git a/src/__snapshots__/loader.test.ts.snap b/src/__snapshots__/loader.test.ts.snap index 7332af3e..a4325846 100644 --- a/src/__snapshots__/loader.test.ts.snap +++ b/src/__snapshots__/loader.test.ts.snap @@ -16,9 +16,11 @@ Array [ `; exports[`graphql-let/loader generates .tsx and .d.ts: .cache/__types__.tsx 1`] = ` -"/* a4d778477a352acf8f4280c7fd1e75fafe04f50f +"/* a3f23e1e0b830904bfe7fb429c06257a8bc3403e * This file is automatically generated by graphql-let. */ +import { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, StorageAdapter as GraphCacheStorageAdapter } from '@urql/exchange-graphcache'; +import { IntrospectionData } from '@urql/exchange-graphcache/dist/types/ast'; import { GraphQLResolveInfo } from 'graphql'; export type Maybe = T | null; export type Exact = { [K in keyof T]: T[K] }; @@ -45,6 +47,40 @@ export type User = { status: Scalars['String']; }; +export type WithTypename = { [K in Exclude]?: T[K] } & { __typename: NonNullable }; + +export type GraphCacheKeysConfig = { + User?: (data: WithTypename) => null | string +} + +export type GraphCacheResolvers = { + Query?: { + viewer?: GraphCacheResolver, Record, WithTypename | string> + }, + User?: { + id?: GraphCacheResolver, Record, Scalars['ID'] | string>, + name?: GraphCacheResolver, Record, Scalars['String'] | string>, + status?: GraphCacheResolver, Record, Scalars['String'] | string> + } +}; + +export type GraphCacheOptimisticUpdaters = { + {} +}; + +export type GraphCacheUpdaters = { + Mutation?: {}, + Subscription?: {}, +}; + +export type GraphCacheConfig = { + schema?: IntrospectionData, + updates?: GraphCacheUpdaters, + keys?: GraphCacheKeysConfig, + optimistic?: GraphCacheOptimisticUpdaters, + resolvers?: GraphCacheResolvers, + storage?: GraphCacheStorageAdapter +}; export type ResolverTypeWrapper = Promise | T; @@ -165,7 +201,7 @@ export type IResolvers = Resolvers; `; exports[`graphql-let/loader generates .tsx and .d.ts: .cache/pages/index-Viewer-Partial.tsx 1`] = ` -"/* 318db4e25e9707ac68da05f12944235ee95a49e0 +"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 * This file is automatically generated by graphql-let. */ import * as Types from '../__types__'; @@ -232,7 +268,7 @@ export type ViewerQueryResult = Apollo.QueryResult = T | null; export declare type Exact = { [K in Exclude]?: T[K] } & { + __typename: NonNullable; +}; +export declare type GraphCacheKeysConfig = { + User?: (data: WithTypename) => null | string; +}; +export declare type GraphCacheResolvers = { + Query?: { + viewer?: GraphCacheResolver, Record, WithTypename | string>; + }; + User?: { + id?: GraphCacheResolver, Record, Scalars['ID'] | string>; + name?: GraphCacheResolver, Record, Scalars['String'] | string>; + status?: GraphCacheResolver, Record, Scalars['String'] | string>; + }; +}; +export declare type GraphCacheOptimisticUpdaters = {}; +export declare type GraphCacheUpdaters = { + Mutation?: {}; + Subscription?: {}; +}; +export declare type GraphCacheConfig = { + schema?: IntrospectionData; + updates?: GraphCacheUpdaters; + keys?: GraphCacheKeysConfig; + optimistic?: GraphCacheOptimisticUpdaters; + resolvers?: GraphCacheResolvers; + storage?: GraphCacheStorageAdapter; +}; export declare type ResolverTypeWrapper = Promise | T; export declare type LegacyStitchingResolver = { fragment: string; @@ -463,7 +532,7 @@ export declare type IResolvers = Resolvers;" `; exports[`graphql-let/loader generates .tsx and .d.ts: node_modules/@types/graphql-let/__generated__/pages/index-Viewer-Partial.d.ts 1`] = ` -"/* 318db4e25e9707ac68da05f12944235ee95a49e0 +"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -517,7 +586,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader generates .tsx and .d.ts: node_modules/@types/graphql-let/__generated__/pages/index-ViewerY-Partial.d.ts 1`] = ` -"/* 4e59730f20e8cab090a59d3945f4fed42a3afefc +"/* 2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -571,9 +640,9 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader generates .tsx and .d.ts: node_modules/@types/graphql-let/index.d.ts 1`] = ` -"import T318db4e25e9707ac68da05f12944235ee95a49e0 from './__generated__/pages/index-Viewer-Partial'; -export function load(load: \`./viewer.graphql\`): T318db4e25e9707ac68da05f12944235ee95a49e0.__GraphQLLetTypeInjection; -import T4e59730f20e8cab090a59d3945f4fed42a3afefc from './__generated__/pages/index-ViewerY-Partial'; +"import T03afcf7b4e2bb8c2930825bdff64c4332cae5f35 from './__generated__/pages/index-Viewer-Partial'; +export function load(load: \`./viewer.graphql\`): T03afcf7b4e2bb8c2930825bdff64c4332cae5f35.__GraphQLLetTypeInjection; +import T2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf from './__generated__/pages/index-ViewerY-Partial'; export function gql(gql: \` # import Partial from './partial.graphql' query ViewerY { @@ -581,7 +650,7 @@ export function gql(gql: \` ...Partial } } -\`): T4e59730f20e8cab090a59d3945f4fed42a3afefc.__GraphQLLetTypeInjection; +\`): T2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf.__GraphQLLetTypeInjection; " `; @@ -592,7 +661,7 @@ export { load } from \\".\\"; `; exports[`graphql-let/loader generates .tsx and .d.ts: pages/viewer.graphql.d.ts 1`] = ` -"/* 318db4e25e9707ac68da05f12944235ee95a49e0 +"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 * This file is automatically generated by graphql-let. */ import * as Types from \\"graphql-let/__generated__/__types__\\"; @@ -727,9 +796,11 @@ Array [ `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: .cache/__types__.tsx 1`] = ` -"/* a4d778477a352acf8f4280c7fd1e75fafe04f50f +"/* a3f23e1e0b830904bfe7fb429c06257a8bc3403e * This file is automatically generated by graphql-let. */ +import { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, StorageAdapter as GraphCacheStorageAdapter } from '@urql/exchange-graphcache'; +import { IntrospectionData } from '@urql/exchange-graphcache/dist/types/ast'; import { GraphQLResolveInfo } from 'graphql'; export type Maybe = T | null; export type Exact = { [K in keyof T]: T[K] }; @@ -756,6 +827,40 @@ export type User = { status: Scalars['String']; }; +export type WithTypename = { [K in Exclude]?: T[K] } & { __typename: NonNullable }; + +export type GraphCacheKeysConfig = { + User?: (data: WithTypename) => null | string +} + +export type GraphCacheResolvers = { + Query?: { + viewer?: GraphCacheResolver, Record, WithTypename | string> + }, + User?: { + id?: GraphCacheResolver, Record, Scalars['ID'] | string>, + name?: GraphCacheResolver, Record, Scalars['String'] | string>, + status?: GraphCacheResolver, Record, Scalars['String'] | string> + } +}; + +export type GraphCacheOptimisticUpdaters = { + {} +}; + +export type GraphCacheUpdaters = { + Mutation?: {}, + Subscription?: {}, +}; + +export type GraphCacheConfig = { + schema?: IntrospectionData, + updates?: GraphCacheUpdaters, + keys?: GraphCacheKeysConfig, + optimistic?: GraphCacheOptimisticUpdaters, + resolvers?: GraphCacheResolvers, + storage?: GraphCacheStorageAdapter +}; export type ResolverTypeWrapper = Promise | T; @@ -876,7 +981,7 @@ export type IResolvers = Resolvers; `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: .cache/pages/index-Viewer-Partial.tsx 1`] = ` -"/* 318db4e25e9707ac68da05f12944235ee95a49e0 +"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 * This file is automatically generated by graphql-let. */ import * as Types from '../__types__'; @@ -943,7 +1048,7 @@ export type ViewerQueryResult = Apollo.QueryResult = T | null; export declare type Exact = { [K in Exclude]?: T[K] } & { + __typename: NonNullable; +}; +export declare type GraphCacheKeysConfig = { + User?: (data: WithTypename) => null | string; +}; +export declare type GraphCacheResolvers = { + Query?: { + viewer?: GraphCacheResolver, Record, WithTypename | string>; + }; + User?: { + id?: GraphCacheResolver, Record, Scalars['ID'] | string>; + name?: GraphCacheResolver, Record, Scalars['String'] | string>; + status?: GraphCacheResolver, Record, Scalars['String'] | string>; + }; +}; +export declare type GraphCacheOptimisticUpdaters = {}; +export declare type GraphCacheUpdaters = { + Mutation?: {}; + Subscription?: {}; +}; +export declare type GraphCacheConfig = { + schema?: IntrospectionData; + updates?: GraphCacheUpdaters; + keys?: GraphCacheKeysConfig; + optimistic?: GraphCacheOptimisticUpdaters; + resolvers?: GraphCacheResolvers; + storage?: GraphCacheStorageAdapter; +}; export declare type ResolverTypeWrapper = Promise | T; export declare type LegacyStitchingResolver = { fragment: string; @@ -1241,7 +1379,7 @@ export declare type IResolvers = Resolvers;" `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: node_modules/@types/graphql-let/__generated__/pages/index-Viewer-Partial.d.ts 1`] = ` -"/* 318db4e25e9707ac68da05f12944235ee95a49e0 +"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -1295,7 +1433,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: node_modules/@types/graphql-let/__generated__/pages/index-ViewerY-Partial.d.ts 1`] = ` -"/* 4e59730f20e8cab090a59d3945f4fed42a3afefc +"/* 2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -1349,7 +1487,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: pages/viewer.graphql.d.ts 1`] = ` -"/* 318db4e25e9707ac68da05f12944235ee95a49e0 +"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 * This file is automatically generated by graphql-let. */ import * as Types from \\"graphql-let/__generated__/__types__\\"; @@ -1397,7 +1535,7 @@ export declare type ViewerQueryResult = Apollo.QueryResult = T | null; export type Exact = { [K in keyof T]: T[K] }; @@ -37,6 +39,40 @@ export type User = { status: Scalars['String']; }; +export type WithTypename = { [K in Exclude]?: T[K] } & { __typename: NonNullable }; + +export type GraphCacheKeysConfig = { + User?: (data: WithTypename) => null | string +} + +export type GraphCacheResolvers = { + Query?: { + viewer?: GraphCacheResolver, Record, WithTypename | string> + }, + User?: { + id?: GraphCacheResolver, Record, Scalars['ID'] | string>, + name?: GraphCacheResolver, Record, Scalars['String'] | string>, + status?: GraphCacheResolver, Record, Scalars['String'] | string> + } +}; + +export type GraphCacheOptimisticUpdaters = { + {} +}; + +export type GraphCacheUpdaters = { + Mutation?: {}, + Subscription?: {}, +}; + +export type GraphCacheConfig = { + schema?: IntrospectionData, + updates?: GraphCacheUpdaters, + keys?: GraphCacheKeysConfig, + optimistic?: GraphCacheOptimisticUpdaters, + resolvers?: GraphCacheResolvers, + storage?: GraphCacheStorageAdapter +}; export type WithIndex = TObject & Record; export type ResolversObject = WithIndex; diff --git a/src/lib/__snapshots__/config.test.ts.snap b/src/lib/__snapshots__/config.test.ts.snap index f5b1b015..41e83822 100644 --- a/src/lib/__snapshots__/config.test.ts.snap +++ b/src/lib/__snapshots__/config.test.ts.snap @@ -46,6 +46,7 @@ Array [ }, }, ], + "schemaPlugins": Array [], "silent": false, "typeInjectEntrypoint": "node_modules/@types/graphql-let/index.d.ts", }, @@ -66,6 +67,7 @@ Object { ], "respectGitIgnore": false, "schema": "**/*.graphql", + "schemaPlugins": Array [], "silent": false, "typeInjectEntrypoint": "typings/yeah.d.ts;", } diff --git a/src/lib/codegen.ts b/src/lib/codegen.ts index da981a39..a32ecc14 100644 --- a/src/lib/codegen.ts +++ b/src/lib/codegen.ts @@ -30,9 +30,11 @@ function getOptionalSchemaPlugins() { // all the presets including plugin options related to it as its spec. // I think it works for many of users, but there could be // cases where you need to configure this more. Issue it then. -function getFixedSchemaConfig() { +function getFixedSchemaConfig( + schemaPlugins: Array>, +) { return { - plugins: ['typescript', ...getOptionalSchemaPlugins()], + plugins: ['typescript', ...schemaPlugins, ...getOptionalSchemaPlugins()], }; } @@ -99,7 +101,7 @@ export function buildCodegenConfig( let opts: ConfiguredOutput; switch (context.type) { case 'schema-import': - opts = getFixedSchemaConfig(); + opts = getFixedSchemaConfig(config.schemaPlugins); break; case 'document-import': diff --git a/src/lib/config.ts b/src/lib/config.ts index 3eee7a87..f736eda4 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -12,6 +12,7 @@ export type PartialGraphqlCodegenOptions = Omit; export type GraphQLLetAdditionalOptions = { plugins: Array>; + schemaPlugins?: Array>; respectGitIgnore?: boolean; cacheDir?: string; TSConfigFile?: string; @@ -72,6 +73,7 @@ You can still have it, but it's redundant and can be problem if the types are ma return { ...raw, + schemaPlugins: raw.schemaPlugins ?? [], // Normalized codegen options documents, // Set graphql-let default values diff --git a/yarn.lock b/yarn.lock index 1b350b66..6e7fd047 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,6 +5,15 @@ __metadata: version: 4 cacheKey: 8 +"@ampproject/remapping@npm:^2.1.0": + version: 2.1.1 + resolution: "@ampproject/remapping@npm:2.1.1" + dependencies: + "@jridgewell/trace-mapping": ^0.3.0 + checksum: cc5cf29833e2b8bdf420821a6e027a35cf6a48605df64ae5095b55cb722581b236554fc8f920138e6da3f7a99ec99273b07ebe2e2bb98b6a4a8d8e33648cac77 + languageName: node + linkType: hard + "@apollo/client@latest": version: 3.3.6 resolution: "@apollo/client@npm:3.3.6" @@ -134,6 +143,15 @@ __metadata: languageName: node linkType: hard +"@babel/code-frame@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/code-frame@npm:7.16.7" + dependencies: + "@babel/highlight": ^7.16.7 + checksum: db2f7faa31bc2c9cf63197b481b30ea57147a5fc1a6fab60e5d6c02cdfbf6de8e17b5121f99917b3dabb5eeb572da078312e70697415940383efc140d4e0808b + languageName: node + linkType: hard + "@babel/compat-data@npm:^7.13.11, @babel/compat-data@npm:^7.13.15, @babel/compat-data@npm:^7.13.8": version: 7.13.15 resolution: "@babel/compat-data@npm:7.13.15" @@ -148,6 +166,13 @@ __metadata: languageName: node linkType: hard +"@babel/compat-data@npm:^7.16.4": + version: 7.17.0 + resolution: "@babel/compat-data@npm:7.17.0" + checksum: fe5afaf529d107a223cd5937dace248464b6df1e9f4ea4031a5723e9571b46a4db1c4ff226bac6351148b1bc02ba1b39cb142662cd235aa99c1dda77882f8c9d + languageName: node + linkType: hard + "@babel/core@npm:7.14.3, @babel/core@npm:^7.0.0, @babel/core@npm:^7.1.0, @babel/core@npm:^7.7.5": version: 7.14.3 resolution: "@babel/core@npm:7.14.3" @@ -217,6 +242,29 @@ __metadata: languageName: node linkType: hard +"@babel/core@npm:7.17.3, @babel/core@npm:^7.14.0": + version: 7.17.3 + resolution: "@babel/core@npm:7.17.3" + dependencies: + "@ampproject/remapping": ^2.1.0 + "@babel/code-frame": ^7.16.7 + "@babel/generator": ^7.17.3 + "@babel/helper-compilation-targets": ^7.16.7 + "@babel/helper-module-transforms": ^7.16.7 + "@babel/helpers": ^7.17.2 + "@babel/parser": ^7.17.3 + "@babel/template": ^7.16.7 + "@babel/traverse": ^7.17.3 + "@babel/types": ^7.17.0 + convert-source-map: ^1.7.0 + debug: ^4.1.0 + gensync: ^1.0.0-beta.2 + json5: ^2.1.2 + semver: ^6.3.0 + checksum: 5a5680888a30db2d5075eb376e25facdd3c2357fe882e6e8b2098a0bf09550bdd1895fa29064af1d4bdd8b6d0964c3bdc08f28c4e1429a5b3597e010a234d15e + languageName: node + linkType: hard + "@babel/generator@npm:^7.12.11, @babel/generator@npm:^7.14.2, @babel/generator@npm:^7.14.3, @babel/generator@npm:^7.5.0": version: 7.14.3 resolution: "@babel/generator@npm:7.14.3" @@ -228,6 +276,17 @@ __metadata: languageName: node linkType: hard +"@babel/generator@npm:^7.14.0, @babel/generator@npm:^7.17.3": + version: 7.17.3 + resolution: "@babel/generator@npm:7.17.3" + dependencies: + "@babel/types": ^7.17.0 + jsesc: ^2.5.1 + source-map: ^0.5.0 + checksum: ddf70e3489976018dfc2da8b9f43ec8c582cac2da681ed4a6227c53b26a9626223e4dca90098b3d3afe43bc67f20160856240e826c56b48e577f34a5a7e22b9f + languageName: node + linkType: hard + "@babel/generator@npm:^7.15.0, @babel/generator@npm:^7.7.2": version: 7.15.0 resolution: "@babel/generator@npm:7.15.0" @@ -329,6 +388,20 @@ __metadata: languageName: node linkType: hard +"@babel/helper-compilation-targets@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-compilation-targets@npm:7.16.7" + dependencies: + "@babel/compat-data": ^7.16.4 + "@babel/helper-validator-option": ^7.16.7 + browserslist: ^4.17.5 + semver: ^6.3.0 + peerDependencies: + "@babel/core": ^7.0.0 + checksum: 7238aaee78c011a42fb5ca92e5eff098752f7b314c2111d7bb9cdd58792fcab1b9c819b59f6a0851dc210dc09dc06b30d130a23982753e70eb3111bc65204842 + languageName: node + linkType: hard + "@babel/helper-create-class-features-plugin@npm:^7.13.0": version: 7.13.0 resolution: "@babel/helper-create-class-features-plugin@npm:7.13.0" @@ -418,6 +491,15 @@ __metadata: languageName: node linkType: hard +"@babel/helper-environment-visitor@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-environment-visitor@npm:7.16.7" + dependencies: + "@babel/types": ^7.16.7 + checksum: c03a10105d9ebd1fe632a77356b2e6e2f3c44edba9a93b0dc3591b6a66bd7a2e323dd9502f9ce96fc6401234abff1907aa877b6674f7826b61c953f7c8204bbe + languageName: node + linkType: hard + "@babel/helper-explode-assignable-expression@npm:^7.14.5": version: 7.14.5 resolution: "@babel/helper-explode-assignable-expression@npm:7.14.5" @@ -460,6 +542,17 @@ __metadata: languageName: node linkType: hard +"@babel/helper-function-name@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-function-name@npm:7.16.7" + dependencies: + "@babel/helper-get-function-arity": ^7.16.7 + "@babel/template": ^7.16.7 + "@babel/types": ^7.16.7 + checksum: fc77cbe7b10cfa2a262d7a37dca575c037f20419dfe0c5d9317f589599ca24beb5f5c1057748011159149eaec47fe32338c6c6412376fcded68200df470161e1 + languageName: node + linkType: hard + "@babel/helper-get-function-arity@npm:^7.12.13": version: 7.12.13 resolution: "@babel/helper-get-function-arity@npm:7.12.13" @@ -487,6 +580,15 @@ __metadata: languageName: node linkType: hard +"@babel/helper-get-function-arity@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-get-function-arity@npm:7.16.7" + dependencies: + "@babel/types": ^7.16.7 + checksum: 25d969fb207ff2ad5f57a90d118f6c42d56a0171022e200aaa919ba7dc95ae7f92ec71cdea6c63ef3629a0dc962ab4c78e09ca2b437185ab44539193f796e0c3 + languageName: node + linkType: hard + "@babel/helper-hoist-variables@npm:^7.14.5": version: 7.14.5 resolution: "@babel/helper-hoist-variables@npm:7.14.5" @@ -505,6 +607,15 @@ __metadata: languageName: node linkType: hard +"@babel/helper-hoist-variables@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-hoist-variables@npm:7.16.7" + dependencies: + "@babel/types": ^7.16.7 + checksum: 6ae1641f4a751cd9045346e3f61c3d9ec1312fd779ab6d6fecfe2a96e59a481ad5d7e40d2a840894c13b3fd6114345b157f9e3062fc5f1580f284636e722de60 + languageName: node + linkType: hard + "@babel/helper-member-expression-to-functions@npm:^7.13.0, @babel/helper-member-expression-to-functions@npm:^7.13.12": version: 7.13.12 resolution: "@babel/helper-member-expression-to-functions@npm:7.13.12" @@ -559,6 +670,15 @@ __metadata: languageName: node linkType: hard +"@babel/helper-module-imports@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-module-imports@npm:7.16.7" + dependencies: + "@babel/types": ^7.16.7 + checksum: ddd2c4a600a2e9a4fee192ab92bf35a627c5461dbab4af31b903d9ba4d6b6e59e0ff3499fde4e2e9a0eebe24906f00b636f8b4d9bd72ff24d50e6618215c3212 + languageName: node + linkType: hard + "@babel/helper-module-transforms@npm:^7.13.0, @babel/helper-module-transforms@npm:^7.14.2": version: 7.14.2 resolution: "@babel/helper-module-transforms@npm:7.14.2" @@ -607,6 +727,22 @@ __metadata: languageName: node linkType: hard +"@babel/helper-module-transforms@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-module-transforms@npm:7.16.7" + dependencies: + "@babel/helper-environment-visitor": ^7.16.7 + "@babel/helper-module-imports": ^7.16.7 + "@babel/helper-simple-access": ^7.16.7 + "@babel/helper-split-export-declaration": ^7.16.7 + "@babel/helper-validator-identifier": ^7.16.7 + "@babel/template": ^7.16.7 + "@babel/traverse": ^7.16.7 + "@babel/types": ^7.16.7 + checksum: 6e930ce776c979f299cdbeaf80187f4ab086d75287b96ecc1c6896d392fcb561065f0d6219fc06fa79b4ceb4bbdc1a9847da8099aba9b077d0a9e583500fb673 + languageName: node + linkType: hard + "@babel/helper-optimise-call-expression@npm:^7.12.13": version: 7.12.13 resolution: "@babel/helper-optimise-call-expression@npm:7.12.13" @@ -733,6 +869,15 @@ __metadata: languageName: node linkType: hard +"@babel/helper-simple-access@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-simple-access@npm:7.16.7" + dependencies: + "@babel/types": ^7.16.7 + checksum: 8d22c46c5ec2ead0686c4d5a3d1d12b5190c59be676bfe0d9d89df62b437b51d1a3df2ccfb8a77dded2e585176ebf12986accb6d45a18cff229eef3b10344f4b + languageName: node + linkType: hard + "@babel/helper-skip-transparent-expression-wrappers@npm:^7.12.1": version: 7.12.1 resolution: "@babel/helper-skip-transparent-expression-wrappers@npm:7.12.1" @@ -787,6 +932,15 @@ __metadata: languageName: node linkType: hard +"@babel/helper-split-export-declaration@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-split-export-declaration@npm:7.16.7" + dependencies: + "@babel/types": ^7.16.7 + checksum: e10aaf135465c55114627951b79115f24bc7af72ecbb58d541d66daf1edaee5dde7cae3ec8c3639afaf74526c03ae3ce723444e3b5b3dc77140c456cd84bcaa1 + languageName: node + linkType: hard + "@babel/helper-validator-identifier@npm:^7.12.11, @babel/helper-validator-identifier@npm:^7.14.0, @babel/helper-validator-identifier@npm:^7.14.8": version: 7.14.8 resolution: "@babel/helper-validator-identifier@npm:7.14.8" @@ -801,6 +955,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-validator-identifier@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-validator-identifier@npm:7.16.7" + checksum: dbb3db9d184343152520a209b5684f5e0ed416109cde82b428ca9c759c29b10c7450657785a8b5c5256aa74acc6da491c1f0cf6b784939f7931ef82982051b69 + languageName: node + linkType: hard + "@babel/helper-validator-option@npm:^7.12.17": version: 7.12.17 resolution: "@babel/helper-validator-option@npm:7.12.17" @@ -815,6 +976,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-validator-option@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/helper-validator-option@npm:7.16.7" + checksum: c5ccc451911883cc9f12125d47be69434f28094475c1b9d2ada7c3452e6ac98a1ee8ddd364ca9e3f9855fcdee96cdeafa32543ebd9d17fee7a1062c202e80570 + languageName: node + linkType: hard + "@babel/helper-wrap-function@npm:^7.14.5": version: 7.14.5 resolution: "@babel/helper-wrap-function@npm:7.14.5" @@ -872,6 +1040,17 @@ __metadata: languageName: node linkType: hard +"@babel/helpers@npm:^7.17.2": + version: 7.17.2 + resolution: "@babel/helpers@npm:7.17.2" + dependencies: + "@babel/template": ^7.16.7 + "@babel/traverse": ^7.17.0 + "@babel/types": ^7.17.0 + checksum: 5fa06bbf59636314fb4098bb2e70cf488e0fb6989553438abab90356357b79976102ac129fb16fc8186893c79e0809de1d90e3304426d6fcdb1750da2b6dff9d + languageName: node + linkType: hard + "@babel/highlight@npm:^7.10.4, @babel/highlight@npm:^7.12.13": version: 7.12.13 resolution: "@babel/highlight@npm:7.12.13" @@ -894,6 +1073,17 @@ __metadata: languageName: node linkType: hard +"@babel/highlight@npm:^7.16.7": + version: 7.16.10 + resolution: "@babel/highlight@npm:7.16.10" + dependencies: + "@babel/helper-validator-identifier": ^7.16.7 + chalk: ^2.0.0 + js-tokens: ^4.0.0 + checksum: 1f1bdd752a90844f4efc22166a46303fb651ba0fd75a06daba3ebae2575ab3edc1da9827c279872a3aaf305f50a18473c5fa1966752726a2b253065fd4c0745e + languageName: node + linkType: hard + "@babel/parser@npm:7.12.11": version: 7.12.11 resolution: "@babel/parser@npm:7.12.11" @@ -921,6 +1111,15 @@ __metadata: languageName: node linkType: hard +"@babel/parser@npm:^7.14.0, @babel/parser@npm:^7.16.7, @babel/parser@npm:^7.17.3": + version: 7.17.3 + resolution: "@babel/parser@npm:7.17.3" + bin: + parser: ./bin/babel-parser.js + checksum: 311869baef97c7630ac3b3c4600da18229b95aa2785b2daab2044384745fe0653070916ade28749fb003f7369a081111ada53e37284ba48d6b5858cbb9e411d1 + languageName: node + linkType: hard + "@babel/parser@npm:^7.14.5, @babel/parser@npm:^7.15.0, @babel/parser@npm:^7.7.2": version: 7.15.3 resolution: "@babel/parser@npm:7.15.3" @@ -2268,6 +2467,17 @@ __metadata: languageName: node linkType: hard +"@babel/template@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/template@npm:7.16.7" + dependencies: + "@babel/code-frame": ^7.16.7 + "@babel/parser": ^7.16.7 + "@babel/types": ^7.16.7 + checksum: 10cd112e89276e00f8b11b55a51c8b2f1262c318283a980f4d6cdb0286dc05734b9aaeeb9f3ad3311900b09bc913e02343fcaa9d4a4f413964aaab04eb84ac4a + languageName: node + linkType: hard + "@babel/traverse@npm:7.12.12": version: 7.12.12 resolution: "@babel/traverse@npm:7.12.12" @@ -2335,6 +2545,24 @@ __metadata: languageName: node linkType: hard +"@babel/traverse@npm:^7.16.7, @babel/traverse@npm:^7.17.0, @babel/traverse@npm:^7.17.3": + version: 7.17.3 + resolution: "@babel/traverse@npm:7.17.3" + dependencies: + "@babel/code-frame": ^7.16.7 + "@babel/generator": ^7.17.3 + "@babel/helper-environment-visitor": ^7.16.7 + "@babel/helper-function-name": ^7.16.7 + "@babel/helper-hoist-variables": ^7.16.7 + "@babel/helper-split-export-declaration": ^7.16.7 + "@babel/parser": ^7.17.3 + "@babel/types": ^7.17.0 + debug: ^4.1.0 + globals: ^11.1.0 + checksum: 780d7ecf711758174989794891af08d378f81febdb8932056c0d9979524bf0298e28f8e7708a872d7781151506c28f56c85c63ea3f1f654662c2fcb8a3eb9fdc + languageName: node + linkType: hard + "@babel/types@npm:7.12.12": version: 7.12.12 resolution: "@babel/types@npm:7.12.12" @@ -2376,6 +2604,16 @@ __metadata: languageName: node linkType: hard +"@babel/types@npm:^7.16.7, @babel/types@npm:^7.17.0": + version: 7.17.0 + resolution: "@babel/types@npm:7.17.0" + dependencies: + "@babel/helper-validator-identifier": ^7.16.7 + to-fast-properties: ^2.0.0 + checksum: 12e5a287986fe557188e87b2c5202223f1dc83d9239a196ab936fdb9f8c1eb0be717ff19f934b5fad4e29a75586d5798f74bed209bccea1c20376b9952056f0e + languageName: node + linkType: hard + "@bcoe/v8-coverage@npm:^0.2.3": version: 0.2.3 resolution: "@bcoe/v8-coverage@npm:0.2.3" @@ -2550,6 +2788,22 @@ __metadata: languageName: node linkType: hard +"@graphql-codegen/plugin-helpers@npm:^2.4.0": + version: 2.4.1 + resolution: "@graphql-codegen/plugin-helpers@npm:2.4.1" + dependencies: + "@graphql-tools/utils": ^8.5.2 + change-case-all: 1.0.14 + common-tags: 1.8.2 + import-from: 4.0.0 + lodash: ~4.17.0 + tslib: ~2.3.0 + peerDependencies: + graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 + checksum: 335cdd412dba70bbcc559cc0e9dc50290b6f737f66fc941619052251ba2c6e20c997663b623b9162ae2523adae97ce5d81d0a56e236ce5f29bae8959a7c575ca + languageName: node + linkType: hard + "@graphql-codegen/typescript-operations@npm:1.18.4": version: 1.18.4 resolution: "@graphql-codegen/typescript-operations@npm:1.18.4" @@ -2597,6 +2851,23 @@ __metadata: languageName: node linkType: hard +"@graphql-codegen/typescript-urql-graphcache@npm:^2.2.4": + version: 2.2.4 + resolution: "@graphql-codegen/typescript-urql-graphcache@npm:2.2.4" + dependencies: + "@graphql-codegen/plugin-helpers": ^2.4.0 + "@graphql-codegen/visitor-plugin-common": 2.6.0 + auto-bind: ~4.0.0 + change-case-all: 1.0.14 + tslib: ~2.3.0 + peerDependencies: + "@urql/exchange-graphcache": ^4.1.1 + graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 + graphql-tag: ^2.0.0 + checksum: 12572129378e4aeb88a65e30e6b0a4df98c900961f801db5b7e52f438ba4963e4e385cbda524dc62e05cd5334931b2341da3e3a377d02c5a4a31473a009cffa8 + languageName: node + linkType: hard + "@graphql-codegen/typescript@npm:1.23.0, @graphql-codegen/typescript@npm:^1.23.0": version: 1.23.0 resolution: "@graphql-codegen/typescript@npm:1.23.0" @@ -2665,6 +2936,26 @@ __metadata: languageName: node linkType: hard +"@graphql-codegen/visitor-plugin-common@npm:2.6.0": + version: 2.6.0 + resolution: "@graphql-codegen/visitor-plugin-common@npm:2.6.0" + dependencies: + "@graphql-codegen/plugin-helpers": ^2.4.0 + "@graphql-tools/optimize": ^1.0.1 + "@graphql-tools/relay-operation-optimizer": ^6.3.7 + "@graphql-tools/utils": ^8.3.0 + auto-bind: ~4.0.0 + change-case-all: 1.0.14 + dependency-graph: ^0.11.0 + graphql-tag: ^2.11.0 + parse-filepath: ^1.0.2 + tslib: ~2.3.0 + peerDependencies: + graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 + checksum: ade3c1321f34950d841e43ed2df9873446b88ac81a8144a4dd8216f364365b9e1b4dbffdad2464e6cc3e83262cad37761bcfcdf3aaaed3b4066ab0f92ca36a5d + languageName: node + linkType: hard + "@graphql-codegen/visitor-plugin-common@npm:^1.20.0": version: 1.21.3 resolution: "@graphql-codegen/visitor-plugin-common@npm:1.21.3" @@ -2926,6 +3217,19 @@ __metadata: languageName: node linkType: hard +"@graphql-tools/relay-operation-optimizer@npm:^6.3.7": + version: 6.4.1 + resolution: "@graphql-tools/relay-operation-optimizer@npm:6.4.1" + dependencies: + "@graphql-tools/utils": ^8.5.1 + relay-compiler: 12.0.0 + tslib: ~2.3.0 + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 + checksum: 479d8375881899b27d3b1bfcb92824004e0757ba8a0bed252d9f77fc258e0ab41379d82e9ec20b823782a2d2bf2a6d68d1e43ea72780cc0fc22a18732de3709c + languageName: node + linkType: hard + "@graphql-tools/schema@npm:^7.0.0, @graphql-tools/schema@npm:^7.1.2": version: 7.1.2 resolution: "@graphql-tools/schema@npm:7.1.2" @@ -2991,6 +3295,17 @@ __metadata: languageName: node linkType: hard +"@graphql-tools/utils@npm:^8.3.0, @graphql-tools/utils@npm:^8.5.1, @graphql-tools/utils@npm:^8.5.2": + version: 8.6.1 + resolution: "@graphql-tools/utils@npm:8.6.1" + dependencies: + tslib: ~2.3.0 + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 + checksum: 1286a2a6160f32038aff4b6cb9da1c844fc2762eec4e6e224238583cf890f335586dccd82cba4bd4e6f50678a6acd678c7043c1bb0d63c4c05c7fd5aa0e177ec + languageName: node + linkType: hard + "@graphql-tools/wrap@npm:^7.0.4": version: 7.0.5 resolution: "@graphql-tools/wrap@npm:7.0.5" @@ -3295,6 +3610,30 @@ __metadata: languageName: node linkType: hard +"@jridgewell/resolve-uri@npm:^3.0.3": + version: 3.0.5 + resolution: "@jridgewell/resolve-uri@npm:3.0.5" + checksum: 1ee652b693da7979ac4007926cc3f0a32b657ffeb913e111f44e5b67153d94a2f28a1d560101cc0cf8087625468293a69a00f634a2914e1a6d0817ba2039a913 + languageName: node + linkType: hard + +"@jridgewell/sourcemap-codec@npm:^1.4.10": + version: 1.4.11 + resolution: "@jridgewell/sourcemap-codec@npm:1.4.11" + checksum: 3b2afaf8400fb07a36db60e901fcce6a746cdec587310ee9035939d89878e57b2dec8173b0b8f63176f647efa352294049a53c49739098eb907ff81fec2547c8 + languageName: node + linkType: hard + +"@jridgewell/trace-mapping@npm:^0.3.0": + version: 0.3.4 + resolution: "@jridgewell/trace-mapping@npm:0.3.4" + dependencies: + "@jridgewell/resolve-uri": ^3.0.3 + "@jridgewell/sourcemap-codec": ^1.4.10 + checksum: ab8bce84bbbc8c34f3ba8325ed926f8f2d3098983c10442a80c55764c4eb6e47d5b92d8ff20a0dd868c3e76a3535651fd8a0138182c290dbfc8396195685c37b + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.4": version: 2.1.4 resolution: "@nodelib/fs.scandir@npm:2.1.4" @@ -5215,6 +5554,43 @@ __metadata: languageName: node linkType: hard +"babel-preset-fbjs@npm:^3.4.0": + version: 3.4.0 + resolution: "babel-preset-fbjs@npm:3.4.0" + dependencies: + "@babel/plugin-proposal-class-properties": ^7.0.0 + "@babel/plugin-proposal-object-rest-spread": ^7.0.0 + "@babel/plugin-syntax-class-properties": ^7.0.0 + "@babel/plugin-syntax-flow": ^7.0.0 + "@babel/plugin-syntax-jsx": ^7.0.0 + "@babel/plugin-syntax-object-rest-spread": ^7.0.0 + "@babel/plugin-transform-arrow-functions": ^7.0.0 + "@babel/plugin-transform-block-scoped-functions": ^7.0.0 + "@babel/plugin-transform-block-scoping": ^7.0.0 + "@babel/plugin-transform-classes": ^7.0.0 + "@babel/plugin-transform-computed-properties": ^7.0.0 + "@babel/plugin-transform-destructuring": ^7.0.0 + "@babel/plugin-transform-flow-strip-types": ^7.0.0 + "@babel/plugin-transform-for-of": ^7.0.0 + "@babel/plugin-transform-function-name": ^7.0.0 + "@babel/plugin-transform-literals": ^7.0.0 + "@babel/plugin-transform-member-expression-literals": ^7.0.0 + "@babel/plugin-transform-modules-commonjs": ^7.0.0 + "@babel/plugin-transform-object-super": ^7.0.0 + "@babel/plugin-transform-parameters": ^7.0.0 + "@babel/plugin-transform-property-literals": ^7.0.0 + "@babel/plugin-transform-react-display-name": ^7.0.0 + "@babel/plugin-transform-react-jsx": ^7.0.0 + "@babel/plugin-transform-shorthand-properties": ^7.0.0 + "@babel/plugin-transform-spread": ^7.0.0 + "@babel/plugin-transform-template-literals": ^7.0.0 + babel-plugin-syntax-trailing-function-commas: ^7.0.0-beta.0 + peerDependencies: + "@babel/core": ^7.0.0 + checksum: b3352cf690729125997f254bc31b9c4db347f8646f1571958ced1c45f0da89439e183e1c88e35397eb0361b9e1fbb1dd8142d3f4647814deb427e53c54f44d5f + languageName: node + linkType: hard + "babel-preset-jest@npm:^27.0.6": version: 27.0.6 resolution: "babel-preset-jest@npm:27.0.6" @@ -5507,6 +5883,21 @@ __metadata: languageName: node linkType: hard +"browserslist@npm:^4.17.5": + version: 4.19.1 + resolution: "browserslist@npm:4.19.1" + dependencies: + caniuse-lite: ^1.0.30001286 + electron-to-chromium: ^1.4.17 + escalade: ^3.1.1 + node-releases: ^2.0.1 + picocolors: ^1.0.0 + bin: + browserslist: cli.js + checksum: c0777fd483691638fd6801e16c9d809e1d65f6d2b06db2e806654be51045cbab1452a89841a2c5caea2cbe19d621b4f1d391cffbb24512aa33280039ab345875 + languageName: node + linkType: hard + "bs-logger@npm:0.x": version: 0.2.6 resolution: "bs-logger@npm:0.2.6" @@ -5756,6 +6147,13 @@ __metadata: languageName: node linkType: hard +"caniuse-lite@npm:^1.0.30001286": + version: 1.0.30001312 + resolution: "caniuse-lite@npm:1.0.30001312" + checksum: 753fb9ea1e02e999430b323a71b5acab5120f3b5fc0161b01669f54a3ef5c5296240b6ae9b79b12a3742e3aed216aa9ee3d5398a23c16d08625ccd376b79545d + languageName: node + linkType: hard + "capital-case@npm:^1.0.4": version: 1.0.4 resolution: "capital-case@npm:1.0.4" @@ -6204,6 +6602,13 @@ __metadata: languageName: node linkType: hard +"common-tags@npm:1.8.2": + version: 1.8.2 + resolution: "common-tags@npm:1.8.2" + checksum: 767a6255a84bbc47df49a60ab583053bb29a7d9687066a18500a516188a062c4e4cd52de341f22de0b07062e699b1b8fe3cfa1cb55b241cb9301aeb4f45b4dff + languageName: node + linkType: hard + "commondir@npm:^1.0.1": version: 1.0.1 resolution: "commondir@npm:1.0.1" @@ -7050,6 +7455,13 @@ __metadata: languageName: node linkType: hard +"electron-to-chromium@npm:^1.4.17": + version: 1.4.71 + resolution: "electron-to-chromium@npm:1.4.71" + checksum: ecb2546eed6b0e95003d787c259de730f32e2f5c0fa2acb27069c0cd21378cbc2a6c7516f4ec677a5960db4e180644f87ed91a729825a238454e31e4e74617db + languageName: node + linkType: hard + "elegant-spinner@npm:^1.0.1": version: 1.0.1 resolution: "elegant-spinner@npm:1.0.1" @@ -8483,6 +8895,7 @@ fsevents@~2.3.1: "@graphql-codegen/typescript-operations": 1.18.4 "@graphql-codegen/typescript-react-apollo": 2.3.1 "@graphql-codegen/typescript-resolvers": 1.19.1 + "@graphql-codegen/typescript-urql-graphcache": ^2.2.4 "@graphql-tools/graphql-file-loader": 6.2.7 "@graphql-tools/import": 6.4.0 "@jest/transform": 27.2.0 @@ -9231,6 +9644,15 @@ fsevents@~2.3.1: languageName: node linkType: hard +"invariant@npm:^2.2.4": + version: 2.2.4 + resolution: "invariant@npm:2.2.4" + dependencies: + loose-envify: ^1.0.0 + checksum: cc3182d793aad82a8d1f0af697b462939cb46066ec48bbf1707c150ad5fad6406137e91a262022c269702e01621f35ef60269f6c0d7fd178487959809acdfb14 + languageName: node + linkType: hard + "ip-regex@npm:^2.1.0": version: 2.1.0 resolution: "ip-regex@npm:2.1.0" @@ -11830,6 +12252,13 @@ fsevents@~2.3.1: languageName: node linkType: hard +"node-releases@npm:^2.0.1": + version: 2.0.2 + resolution: "node-releases@npm:2.0.2" + checksum: da858bf86b4d512842379749f5a5e4196ddab05ba18ffcf29f05bf460beceaca927f070f4430bb5046efec18941ddbc85e4c5fdbb83afc28a38dd6069a2f255e + languageName: node + linkType: hard + "noms@npm:0.0.0": version: 0.0.0 resolution: "noms@npm:0.0.0" @@ -12477,6 +12906,13 @@ fsevents@~2.3.1: languageName: node linkType: hard +"picocolors@npm:^1.0.0": + version: 1.0.0 + resolution: "picocolors@npm:1.0.0" + checksum: a2e8092dd86c8396bdba9f2b5481032848525b3dc295ce9b57896f931e63fc16f79805144321f72976383fc249584672a75cc18d6777c6b757603f372f745981 + languageName: node + linkType: hard + "picomatch@npm:^2.0.4, picomatch@npm:^2.0.5, picomatch@npm:^2.2.1": version: 2.2.2 resolution: "picomatch@npm:2.2.2" @@ -13235,6 +13671,35 @@ fsevents@~2.3.1: languageName: node linkType: hard +"relay-compiler@npm:12.0.0": + version: 12.0.0 + resolution: "relay-compiler@npm:12.0.0" + dependencies: + "@babel/core": ^7.14.0 + "@babel/generator": ^7.14.0 + "@babel/parser": ^7.14.0 + "@babel/runtime": ^7.0.0 + "@babel/traverse": ^7.14.0 + "@babel/types": ^7.0.0 + babel-preset-fbjs: ^3.4.0 + chalk: ^4.0.0 + fb-watchman: ^2.0.0 + fbjs: ^3.0.0 + glob: ^7.1.1 + immutable: ~3.7.6 + invariant: ^2.2.4 + nullthrows: ^1.1.1 + relay-runtime: 12.0.0 + signedsource: ^1.0.0 + yargs: ^15.3.1 + peerDependencies: + graphql: ^15.0.0 + bin: + relay-compiler: bin/relay-compiler + checksum: 3a7245adda15b866893438474725834381046e04ddd209810ca6077364360da718131e97fa9cb651e8991da6e4b889c9a48af9fb85cea7311561a5120f9a4d60 + languageName: node + linkType: hard + "relay-runtime@npm:10.1.0": version: 10.1.0 resolution: "relay-runtime@npm:10.1.0" @@ -13245,6 +13710,17 @@ fsevents@~2.3.1: languageName: node linkType: hard +"relay-runtime@npm:12.0.0": + version: 12.0.0 + resolution: "relay-runtime@npm:12.0.0" + dependencies: + "@babel/runtime": ^7.0.0 + fbjs: ^3.0.0 + invariant: ^2.2.4 + checksum: 51cdc8a5e04188982452ae4e7c6ac7d6375ee769130d24ce8e8f9cdd45aa7e11ecd68670f56e30dcee1b4974585e88ecce19e69a9868b80cda0db7678c3b8f0a + languageName: node + linkType: hard + "remark-cli@npm:9.0.0": version: 9.0.0 resolution: "remark-cli@npm:9.0.0" From 45c01dfdcf73b15d1ca5047ba70e03c602e7037d Mon Sep 17 00:00:00 2001 From: Ville Saukkonen Date: Tue, 15 Feb 2022 23:59:46 +0200 Subject: [PATCH 2/4] add test for the config --- .../config/.graphql-let-schema-plugins.yml | 9 ++++++ src/lib/__snapshots__/config.test.ts.snap | 32 +++++++++++++++++++ src/lib/config.test.ts | 5 +++ 3 files changed, 46 insertions(+) create mode 100644 src/lib/__fixtures/config/.graphql-let-schema-plugins.yml diff --git a/src/lib/__fixtures/config/.graphql-let-schema-plugins.yml b/src/lib/__fixtures/config/.graphql-let-schema-plugins.yml new file mode 100644 index 00000000..e88dc3ae --- /dev/null +++ b/src/lib/__fixtures/config/.graphql-let-schema-plugins.yml @@ -0,0 +1,9 @@ +schema: + - ${GRAPHQL_SERVER_ENDPOINT}: + headers: + Authorization: ${GRAPHQL_SERVER_TOKEN} +documents: "**/*.graphql" +plugins: + - typescript +schemaPlugins: + - typescript-urql-graphcache diff --git a/src/lib/__snapshots__/config.test.ts.snap b/src/lib/__snapshots__/config.test.ts.snap index 41e83822..b24f22d6 100644 --- a/src/lib/__snapshots__/config.test.ts.snap +++ b/src/lib/__snapshots__/config.test.ts.snap @@ -54,6 +54,38 @@ Array [ ] `; +exports[`config.ts loads config with default values 2`] = ` +Array [ + Object { + "TSConfigFile": "tsconfig.json", + "cacheDir": "node_modules/.cache/graphql-let", + "documents": Array [ + "**/*.graphql", + ], + "generateOptions": Object {}, + "plugins": Array [ + "typescript", + ], + "respectGitIgnore": true, + "schema": Array [ + Object { + "https://yeah/graphql": Object { + "headers": Object { + "Authorization": "blaa", + }, + }, + }, + ], + "schemaPlugins": Array [ + "typescript-urql-graphcache", + ], + "silent": false, + "typeInjectEntrypoint": "node_modules/@types/graphql-let/index.d.ts", + }, + "4933856f4c73056601c24f36aceabc5dcb014d12", +] +`; + exports[`config.ts overwrite default values 1`] = ` Object { "TSConfigFile": "tsconfig.yeah.json;", diff --git a/src/lib/config.test.ts b/src/lib/config.test.ts index 58198e97..25d4192c 100644 --- a/src/lib/config.test.ts +++ b/src/lib/config.test.ts @@ -20,6 +20,11 @@ describe('config.ts', () => { expect(actual).toMatchSnapshot(); }); + test('loads config with default values', async () => { + const actual = await loadConfig(cwd, '.graphql-let-schema-plugins.yml'); + expect(actual).toMatchSnapshot(); + }); + test('interpolates environment variables', () => { const [{ schema }] = loadConfigSync(cwd, '.graphql-let-envvar.yml'); expect(schema).toMatchSnapshot(); From 88e9c52b1a0a8cd828fd3e4f5d7edd09e80a4b1c Mon Sep 17 00:00:00 2001 From: Ville Saukkonen Date: Tue, 15 Feb 2022 23:59:57 +0200 Subject: [PATCH 3/4] add readme mention --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1407082..f13b6f52 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ yarn graphql-let init Next, add [graphql-codegen plugins](https://graphql-code-generator.com/docs/plugins/index) in it. **Please note that you have to generate a TypeScript source** by the -plugins. +plugins. schemaPlugins are used for plugins that generates types from the schema and the result ends up into `__types__`. Edit it like this: @@ -187,6 +187,8 @@ Edit it like this: plugins: + - typescript-operations + - typescript-react-apollo ++ schemaPlugins: ++ - typescript-urql-graphcache ``` ### 3. Check your `cacheDir` From 3d0557c588966567b116fb7f66eed6d20629bf16 Mon Sep 17 00:00:00 2001 From: Ville Saukkonen Date: Wed, 16 Feb 2022 11:18:09 +0200 Subject: [PATCH 4/4] get rid of outdated way of attaching schemaPlugins --- src/__fixtures/gen/6_babel/.graphql-let.yml | 2 + src/__fixtures/loader/basic/.graphql-let.yml | 1 + src/__snapshots__/gen.test.ts.snap | 42 +++---- src/__snapshots__/loader.test.ts.snap | 44 +++---- src/lib/__snapshots__/codegen.test.ts.snap | 121 +------------------ src/lib/codegen.ts | 29 +---- 6 files changed, 50 insertions(+), 189 deletions(-) diff --git a/src/__fixtures/gen/6_babel/.graphql-let.yml b/src/__fixtures/gen/6_babel/.graphql-let.yml index a837d4aa..37d88804 100644 --- a/src/__fixtures/gen/6_babel/.graphql-let.yml +++ b/src/__fixtures/gen/6_babel/.graphql-let.yml @@ -2,6 +2,8 @@ schema: "**/*.graphqls" documents: - "**/*.graphql" - "**/*.tsx" +schemaPlugins: + - typescript-resolvers plugins: - typescript-operations - typescript-react-apollo diff --git a/src/__fixtures/loader/basic/.graphql-let.yml b/src/__fixtures/loader/basic/.graphql-let.yml index 5e575fc0..8acf130b 100644 --- a/src/__fixtures/loader/basic/.graphql-let.yml +++ b/src/__fixtures/loader/basic/.graphql-let.yml @@ -7,5 +7,6 @@ plugins: - typescript-react-apollo schemaPlugins: - typescript-urql-graphcache + - typescript-resolvers respectGitIgnore: true cacheDir: .cache diff --git a/src/__snapshots__/gen.test.ts.snap b/src/__snapshots__/gen.test.ts.snap index 3a605bd0..d9414241 100644 --- a/src/__snapshots__/gen.test.ts.snap +++ b/src/__snapshots__/gen.test.ts.snap @@ -198,7 +198,7 @@ Array [ `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/.cache/graphql-let/__types__.tsx 1`] = ` -"/* 27569d60e28f4880a230cd26da042acd54d303af +"/* a93b1a87b4325d2ac4bb4ef1a6208772948997e2 * This file is automatically generated by graphql-let. */ import { GraphQLResolveInfo } from 'graphql'; @@ -347,7 +347,7 @@ export type IResolvers = Resolvers; `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/.cache/graphql-let/pages/from-macro-ViewerFromMacro-Partial.tsx 1`] = ` -"/* e5e32f3604cc484c9547619cce01529a47277836 +"/* 52275cd982a535a506c369006ea690794be91370 * This file is automatically generated by graphql-let. */ import * as Types from '../__types__'; @@ -414,7 +414,7 @@ export type ViewerFromMacroQueryResult = Apollo.QueryResult = Resolvers;" `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/@types/graphql-let/__generated__/pages/from-macro-ViewerFromMacro-Partial.d.ts 1`] = ` -"/* e5e32f3604cc484c9547619cce01529a47277836 +"/* 52275cd982a535a506c369006ea690794be91370 * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -920,7 +920,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/@types/graphql-let/__generated__/pages/from-macro-ViewerFromMacro2-Partial.d.ts 1`] = ` -"/* 4e25fb0a41363bd635210a286f24ab81849f99b9 +"/* 90731eda4348da4125c658d0fcf9518973e54b0f * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -974,7 +974,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/@types/graphql-let/__generated__/pages/index-Viewer-Partial.d.ts 1`] = ` -"/* b808b9cd1cc51ee9dacb9a8ad4ad31c6816d8169 +"/* 8b80f16d5f0a53d6844dd8a8a472b72847b65ef2 * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -1028,7 +1028,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/@types/graphql-let/__generated__/pages/index-ViewerY-Partial.d.ts 1`] = ` -"/* b045ed587f3be8783c00b58d261fec11d1a550f8 +"/* 99c896d3cdd73c1f6e2d3cbebcd177967aef8ac1 * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -1082,9 +1082,9 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`"graphql-let" command documents: **/*.tsx generates .d.ts for babel: node_modules/@types/graphql-let/index.d.ts 1`] = ` -"import Te5e32f3604cc484c9547619cce01529a47277836 from './__generated__/pages/from-macro-ViewerFromMacro-Partial'; -export function load(load: \`./viewer-from-macro.graphql\`): Te5e32f3604cc484c9547619cce01529a47277836.__GraphQLLetTypeInjection; -import T4e25fb0a41363bd635210a286f24ab81849f99b9 from './__generated__/pages/from-macro-ViewerFromMacro2-Partial'; +"import T52275cd982a535a506c369006ea690794be91370 from './__generated__/pages/from-macro-ViewerFromMacro-Partial'; +export function load(load: \`./viewer-from-macro.graphql\`): T52275cd982a535a506c369006ea690794be91370.__GraphQLLetTypeInjection; +import T90731eda4348da4125c658d0fcf9518973e54b0f from './__generated__/pages/from-macro-ViewerFromMacro2-Partial'; export function gql(gql: \` # import Partial from './partial.graphql' query ViewerFromMacro2 { @@ -1092,10 +1092,10 @@ export function gql(gql: \` ...Partial } } -\`): T4e25fb0a41363bd635210a286f24ab81849f99b9.__GraphQLLetTypeInjection; -import Tb808b9cd1cc51ee9dacb9a8ad4ad31c6816d8169 from './__generated__/pages/index-Viewer-Partial'; -export function load(load: \`./viewer.graphql\`): Tb808b9cd1cc51ee9dacb9a8ad4ad31c6816d8169.__GraphQLLetTypeInjection; -import Tb045ed587f3be8783c00b58d261fec11d1a550f8 from './__generated__/pages/index-ViewerY-Partial'; +\`): T90731eda4348da4125c658d0fcf9518973e54b0f.__GraphQLLetTypeInjection; +import T8b80f16d5f0a53d6844dd8a8a472b72847b65ef2 from './__generated__/pages/index-Viewer-Partial'; +export function load(load: \`./viewer.graphql\`): T8b80f16d5f0a53d6844dd8a8a472b72847b65ef2.__GraphQLLetTypeInjection; +import T99c896d3cdd73c1f6e2d3cbebcd177967aef8ac1 from './__generated__/pages/index-ViewerY-Partial'; export function gql(gql: \` # import Partial from './partial.graphql' query ViewerY { @@ -1103,7 +1103,7 @@ export function gql(gql: \` ...Partial } } -\`): Tb045ed587f3be8783c00b58d261fec11d1a550f8.__GraphQLLetTypeInjection; +\`): T99c896d3cdd73c1f6e2d3cbebcd177967aef8ac1.__GraphQLLetTypeInjection; " `; diff --git a/src/__snapshots__/loader.test.ts.snap b/src/__snapshots__/loader.test.ts.snap index a4325846..739ce6d0 100644 --- a/src/__snapshots__/loader.test.ts.snap +++ b/src/__snapshots__/loader.test.ts.snap @@ -16,7 +16,7 @@ Array [ `; exports[`graphql-let/loader generates .tsx and .d.ts: .cache/__types__.tsx 1`] = ` -"/* a3f23e1e0b830904bfe7fb429c06257a8bc3403e +"/* 75d7e2a98bc6fe190a99eca03ce69488c4b6373c * This file is automatically generated by graphql-let. */ import { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, StorageAdapter as GraphCacheStorageAdapter } from '@urql/exchange-graphcache'; @@ -201,7 +201,7 @@ export type IResolvers = Resolvers; `; exports[`graphql-let/loader generates .tsx and .d.ts: .cache/pages/index-Viewer-Partial.tsx 1`] = ` -"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 +"/* 8d50d79c46699b4f84f5acf54ec2294dc30f3e4c * This file is automatically generated by graphql-let. */ import * as Types from '../__types__'; @@ -268,7 +268,7 @@ export type ViewerQueryResult = Apollo.QueryResult = Resolvers;" `; exports[`graphql-let/loader generates .tsx and .d.ts: node_modules/@types/graphql-let/__generated__/pages/index-Viewer-Partial.d.ts 1`] = ` -"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 +"/* 8d50d79c46699b4f84f5acf54ec2294dc30f3e4c * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -586,7 +586,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader generates .tsx and .d.ts: node_modules/@types/graphql-let/__generated__/pages/index-ViewerY-Partial.d.ts 1`] = ` -"/* 2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf +"/* b07a9c68cf38a049fbd12b3ae646b1e93e380e0b * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -640,9 +640,9 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader generates .tsx and .d.ts: node_modules/@types/graphql-let/index.d.ts 1`] = ` -"import T03afcf7b4e2bb8c2930825bdff64c4332cae5f35 from './__generated__/pages/index-Viewer-Partial'; -export function load(load: \`./viewer.graphql\`): T03afcf7b4e2bb8c2930825bdff64c4332cae5f35.__GraphQLLetTypeInjection; -import T2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf from './__generated__/pages/index-ViewerY-Partial'; +"import T8d50d79c46699b4f84f5acf54ec2294dc30f3e4c from './__generated__/pages/index-Viewer-Partial'; +export function load(load: \`./viewer.graphql\`): T8d50d79c46699b4f84f5acf54ec2294dc30f3e4c.__GraphQLLetTypeInjection; +import Tb07a9c68cf38a049fbd12b3ae646b1e93e380e0b from './__generated__/pages/index-ViewerY-Partial'; export function gql(gql: \` # import Partial from './partial.graphql' query ViewerY { @@ -650,7 +650,7 @@ export function gql(gql: \` ...Partial } } -\`): T2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf.__GraphQLLetTypeInjection; +\`): Tb07a9c68cf38a049fbd12b3ae646b1e93e380e0b.__GraphQLLetTypeInjection; " `; @@ -661,7 +661,7 @@ export { load } from \\".\\"; `; exports[`graphql-let/loader generates .tsx and .d.ts: pages/viewer.graphql.d.ts 1`] = ` -"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 +"/* 8d50d79c46699b4f84f5acf54ec2294dc30f3e4c * This file is automatically generated by graphql-let. */ import * as Types from \\"graphql-let/__generated__/__types__\\"; @@ -796,7 +796,7 @@ Array [ `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: .cache/__types__.tsx 1`] = ` -"/* a3f23e1e0b830904bfe7fb429c06257a8bc3403e +"/* 75d7e2a98bc6fe190a99eca03ce69488c4b6373c * This file is automatically generated by graphql-let. */ import { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, StorageAdapter as GraphCacheStorageAdapter } from '@urql/exchange-graphcache'; @@ -981,7 +981,7 @@ export type IResolvers = Resolvers; `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: .cache/pages/index-Viewer-Partial.tsx 1`] = ` -"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 +"/* 8d50d79c46699b4f84f5acf54ec2294dc30f3e4c * This file is automatically generated by graphql-let. */ import * as Types from '../__types__'; @@ -1048,7 +1048,7 @@ export type ViewerQueryResult = Apollo.QueryResult = Resolvers;" `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: node_modules/@types/graphql-let/__generated__/pages/index-Viewer-Partial.d.ts 1`] = ` -"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 +"/* 8d50d79c46699b4f84f5acf54ec2294dc30f3e4c * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -1433,7 +1433,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: node_modules/@types/graphql-let/__generated__/pages/index-ViewerY-Partial.d.ts 1`] = ` -"/* 2bcd30ecc94d2197ef6e6e7ac7d760b1a0c24ecf +"/* b07a9c68cf38a049fbd12b3ae646b1e93e380e0b * This file is automatically generated by graphql-let. */ import * as Types from \\"../__types__\\"; @@ -1487,7 +1487,7 @@ export declare type __GraphQLLetTypeInjection = { `; exports[`graphql-let/loader runs well for simultaneous execution, assuming SSR: pages/viewer.graphql.d.ts 1`] = ` -"/* 03afcf7b4e2bb8c2930825bdff64c4332cae5f35 +"/* 8d50d79c46699b4f84f5acf54ec2294dc30f3e4c * This file is automatically generated by graphql-let. */ import * as Types from \\"graphql-let/__generated__/__types__\\"; @@ -1535,7 +1535,7 @@ export declare type ViewerQueryResult = Apollo.QueryResult = T | null; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; @@ -72,125 +71,7 @@ export type GraphCacheConfig = { optimistic?: GraphCacheOptimisticUpdaters, resolvers?: GraphCacheResolvers, storage?: GraphCacheStorageAdapter -}; -export type WithIndex = TObject & Record; -export type ResolversObject = WithIndex; - -export type ResolverTypeWrapper = Promise | T; - - -export type LegacyStitchingResolver = { - fragment: string; - resolve: ResolverFn; -}; - -export type NewStitchingResolver = { - selectionSet: string; - resolve: ResolverFn; -}; -export type StitchingResolver = LegacyStitchingResolver | NewStitchingResolver; -export type Resolver = - | ResolverFn - | StitchingResolver; - -export type ResolverFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => Promise | TResult; - -export type SubscriptionSubscribeFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => AsyncIterator | Promise>; - -export type SubscriptionResolveFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -export interface SubscriptionSubscriberObject { - subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; - resolve?: SubscriptionResolveFn; -} - -export interface SubscriptionResolverObject { - subscribe: SubscriptionSubscribeFn; - resolve: SubscriptionResolveFn; -} - -export type SubscriptionObject = - | SubscriptionSubscriberObject - | SubscriptionResolverObject; - -export type SubscriptionResolver = - | ((...args: any[]) => SubscriptionObject) - | SubscriptionObject; - -export type TypeResolveFn = ( - parent: TParent, - context: TContext, - info: GraphQLResolveInfo -) => Maybe | Promise>; - -export type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; - -export type NextResolverFn = () => Promise; - -export type DirectiveResolverFn = ( - next: NextResolverFn, - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => TResult | Promise; - -/** Mapping between all available schema types and the resolvers types */ -export type ResolversTypes = ResolversObject<{ - Query: ResolverTypeWrapper<{}>; - User: ResolverTypeWrapper; - ID: ResolverTypeWrapper; - String: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; -}>; - -/** Mapping between all available schema types and the resolvers parents */ -export type ResolversParentTypes = ResolversObject<{ - Query: {}; - User: User; - ID: Scalars['ID']; - String: Scalars['String']; - Boolean: Scalars['Boolean']; -}>; - -export type QueryResolvers = ResolversObject<{ - viewer?: Resolver, ParentType, ContextType>; -}>; - -export type UserResolvers = ResolversObject<{ - id?: Resolver; - name?: Resolver; - status?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}>; - -export type Resolvers = ResolversObject<{ - Query?: QueryResolvers; - User?: UserResolvers; -}>; - - -/** - * @deprecated - * Use \\"Resolvers\\" root object instead. If you wish to get \\"IResolvers\\", add \\"typesPrefix: I\\" to your config. - */ -export type IResolvers = Resolvers; -" +};" `; exports[`graphql-codegen.ts works: .cache/pages/viewer.graphql.tsx 1`] = ` diff --git a/src/lib/codegen.ts b/src/lib/codegen.ts index a32ecc14..2da380eb 100644 --- a/src/lib/codegen.ts +++ b/src/lib/codegen.ts @@ -13,31 +13,6 @@ import { printError } from './print'; import { CodegenContext, getSchemaImportContext, isAllSkip } from './types'; import ConfiguredOutput = Types.ConfiguredOutput; -const OPTIONAL_SCHEMA_PLUGINS = ['typescript-resolvers']; -function getOptionalSchemaPlugins() { - const plugins: string[] = []; - for (const c of OPTIONAL_SCHEMA_PLUGINS) { - try { - require(`@graphql-codegen/${c}`); - plugins.push(c); - // eslint-disable-next-line no-empty - } catch (e) {} - } - return plugins; -} - -// To avoid unnecessary complexity, graphql-let controls -// all the presets including plugin options related to it as its spec. -// I think it works for many of users, but there could be -// cases where you need to configure this more. Issue it then. -function getFixedSchemaConfig( - schemaPlugins: Array>, -) { - return { - plugins: ['typescript', ...schemaPlugins, ...getOptionalSchemaPlugins()], - }; -} - function createFixedDocumentPresetConfig( context: CodegenContext, execContext: ExecContext, @@ -101,7 +76,9 @@ export function buildCodegenConfig( let opts: ConfiguredOutput; switch (context.type) { case 'schema-import': - opts = getFixedSchemaConfig(config.schemaPlugins); + opts = { + plugins: ['typescript', ...config.schemaPlugins], + }; break; case 'document-import':