diff --git a/dev-test/githunt/types.noNamespaces.ts b/dev-test/githunt/types.noNamespaces.ts index b00c27a427d..40b5849d11c 100644 --- a/dev-test/githunt/types.noNamespaces.ts +++ b/dev-test/githunt/types.noNamespaces.ts @@ -81,7 +81,7 @@ export type Maybe = T | null; createdAt: number; - comments: CommentComments[]; + comments: (Maybe)[]; commentCount: number; @@ -144,7 +144,7 @@ export type Maybe = T | null; currentUser: Maybe; - feed: Maybe; + feed: Maybe<(Maybe)[]>; }; export type FeedCurrentUser = { diff --git a/dev-test/githunt/types.reactApollo.noNamespaces.tsx b/dev-test/githunt/types.reactApollo.noNamespaces.tsx index 00ee16952e7..40be3600bf2 100644 --- a/dev-test/githunt/types.reactApollo.noNamespaces.tsx +++ b/dev-test/githunt/types.reactApollo.noNamespaces.tsx @@ -82,7 +82,7 @@ export type Maybe = T | null; createdAt: number; - comments: CommentComments[]; + comments: (Maybe)[]; commentCount: number; @@ -145,7 +145,7 @@ export type Maybe = T | null; currentUser: Maybe; - feed: Maybe; + feed: Maybe<(Maybe)[]>; } export type FeedCurrentUser = { @@ -300,10 +300,11 @@ export type Maybe = T | null; vote_value: number; } + + import gql from 'graphql-tag'; + import * as React from 'react'; import * as ReactApollo from 'react-apollo'; -import * as React from 'react'; -import gql from 'graphql-tag'; diff --git a/dev-test/githunt/types.reactApollo.tsx b/dev-test/githunt/types.reactApollo.tsx index ea9d625a1fa..da532423a64 100644 --- a/dev-test/githunt/types.reactApollo.tsx +++ b/dev-test/githunt/types.reactApollo.tsx @@ -322,10 +322,11 @@ export namespace VoteButtons { } } + + import gql from 'graphql-tag'; + import * as React from 'react'; import * as ReactApollo from 'react-apollo'; -import * as React from 'react'; -import gql from 'graphql-tag'; diff --git a/dev-test/test-message/types.reactApollo.noNamespaces.tsx b/dev-test/test-message/types.reactApollo.noNamespaces.tsx index a0f4049f949..2a5187d26fe 100644 --- a/dev-test/test-message/types.reactApollo.noNamespaces.tsx +++ b/dev-test/test-message/types.reactApollo.noNamespaces.tsx @@ -21,7 +21,7 @@ export interface CreateMessageInput { export type GetMessagesQuery = { __typename?: "Query"; - messages: Maybe; + messages: Maybe<(Maybe)[]>; } export type GetMessagesMessages = { @@ -95,10 +95,11 @@ export interface CreateMessageInput { id: string; } + + import gql from 'graphql-tag'; + import * as React from 'react'; import * as ReactApollo from 'react-apollo'; -import * as React from 'react'; -import gql from 'graphql-tag'; diff --git a/dev-test/test-message/types.stencilApollo.noNamespaces.tsx b/dev-test/test-message/types.stencilApollo.noNamespaces.tsx index 84a2d2df8c8..bdf0c208169 100644 --- a/dev-test/test-message/types.stencilApollo.noNamespaces.tsx +++ b/dev-test/test-message/types.stencilApollo.noNamespaces.tsx @@ -21,7 +21,7 @@ export interface CreateMessageInput { export type GetMessagesQuery = { __typename?: "Query"; - messages: Maybe; + messages: Maybe<(Maybe)[]>; } export type GetMessagesMessages = { @@ -95,7 +95,6 @@ export interface CreateMessageInput { id: string; } -import { FunctionalComponent } from '@stencil/core'; import gql from 'graphql-tag'; @@ -119,20 +118,11 @@ import gql from 'graphql-tag'; `; - export interface ComponentProps { + export interface GetMessagesComponentProps { variables ?: GetMessagesVariables; onReady ?: import('stencil-apollo/dist/types/components/apollo-query/types').OnQueryReadyFn; } - export const GetMessagesComponent: FunctionalComponent = (props, children) => { - return ( - - {children} - - ); - } + export const GetMessagesComponent = (props: GetMessagesComponentProps) => ; export const CreateMessageDocument = gql` mutation CreateMessage($args: CreateMessageInput!) { createMessage(args: $args) { @@ -143,20 +133,11 @@ import gql from 'graphql-tag'; `; - export interface ComponentProps { + export interface CreateMessageComponentProps { variables ?: CreateMessageVariables; onReady ?: import('stencil-apollo/dist/types/components/apollo-mutation/types').OnMutationReadyFn; } - export const CreateMessageComponent: FunctionalComponent = (props, children) => { - return ( - - {children} - - ); - } + export const CreateMessageComponent = (props: CreateMessageComponentProps) => ; export const DeclineDocument = gql` mutation Decline($id: ID!, $reason: String!) { decline(id: $id, reason: $reason) { @@ -167,20 +148,11 @@ import gql from 'graphql-tag'; `; - export interface ComponentProps { + export interface DeclineComponentProps { variables ?: DeclineVariables; onReady ?: import('stencil-apollo/dist/types/components/apollo-mutation/types').OnMutationReadyFn; } - export const DeclineComponent: FunctionalComponent = (props, children) => { - return ( - - {children} - - ); - } + export const DeclineComponent = (props: DeclineComponentProps) => ; export const ApproveDocument = gql` mutation Approve($id: ID!) { approve(id: $id) { @@ -191,20 +163,11 @@ import gql from 'graphql-tag'; `; - export interface ComponentProps { + export interface ApproveComponentProps { variables ?: ApproveVariables; onReady ?: import('stencil-apollo/dist/types/components/apollo-mutation/types').OnMutationReadyFn; } - export const ApproveComponent: FunctionalComponent = (props, children) => { - return ( - - {children} - - ); - } + export const ApproveComponent = (props: ApproveComponentProps) => ; export const EscalateDocument = gql` mutation Escalate($id: ID!) { escalate(id: $id) { @@ -215,17 +178,8 @@ import gql from 'graphql-tag'; `; - export interface ComponentProps { + export interface EscalateComponentProps { variables ?: EscalateVariables; onReady ?: import('stencil-apollo/dist/types/components/apollo-mutation/types').OnMutationReadyFn; } - export const EscalateComponent: FunctionalComponent = (props, children) => { - return ( - - {children} - - ); - } + export const EscalateComponent = (props: EscalateComponentProps) => ; diff --git a/dev-test/test-mongodb/types.ts b/dev-test/test-mongodb/types.ts index a74ad9fc76e..9f4e2e2cbd8 100644 --- a/dev-test/test-mongodb/types.ts +++ b/dev-test/test-mongodb/types.ts @@ -236,35 +236,35 @@ import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from ' -export type Resolver = ( +export type Resolver = ( parent: Parent, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Promise | Result; -export interface ISubscriptionResolverObject { +export interface ISubscriptionResolverObject { subscribe( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): AsyncIterator | Promise>; resolve?( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): R | Result | Promise; } -export type SubscriptionResolver = - | ((...args: any[]) => ISubscriptionResolverObject) - | ISubscriptionResolverObject; +export type SubscriptionResolver = + | ((...args: any[]) => ISubscriptionResolverObject) + | ISubscriptionResolverObject; -export type TypeResolveFn = ( +export type TypeResolveFn = ( parent: Parent, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Maybe; @@ -280,51 +280,51 @@ export type DirectiveResolverFn = ( export namespace PostResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver, TypeParent, Context>; + id?: IdResolver, TypeParent, TContext>; - title?: TitleResolver, TypeParent, Context>; + title?: TitleResolver, TypeParent, TContext>; - content?: ContentResolver, TypeParent, Context>; + content?: ContentResolver, TypeParent, TContext>; - createdAt?: CreatedAtResolver, TypeParent, Context>; + createdAt?: CreatedAtResolver, TypeParent, TContext>; - author?: AuthorResolver, TypeParent, Context>; + author?: AuthorResolver, TypeParent, TContext>; } - export type IdResolver, Parent = Post, Context = {}> = Resolver; - export type TitleResolver, Parent = Post, Context = {}> = Resolver; - export type ContentResolver, Parent = Post, Context = {}> = Resolver; - export type CreatedAtResolver, Parent = Post, Context = {}> = Resolver; - export type AuthorResolver, Parent = Post, Context = {}> = Resolver; + export type IdResolver, Parent = Post, TContext = {}> = Resolver; + export type TitleResolver, Parent = Post, TContext = {}> = Resolver; + export type ContentResolver, Parent = Post, TContext = {}> = Resolver; + export type CreatedAtResolver, Parent = Post, TContext = {}> = Resolver; + export type AuthorResolver, Parent = Post, TContext = {}> = Resolver; } export namespace AdminUserResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver, TypeParent, Context>; + id?: IdResolver, TypeParent, TContext>; - username?: UsernameResolver, TypeParent, Context>; + username?: UsernameResolver, TypeParent, TContext>; - role?: RoleResolver, TypeParent, Context>; + role?: RoleResolver, TypeParent, TContext>; - likedPosts?: LikedPostsResolver)[]>, TypeParent, Context>; + likedPosts?: LikedPostsResolver)[]>, TypeParent, TContext>; - followerUsers?: FollowerUsersResolver)[]>, TypeParent, Context>; + followerUsers?: FollowerUsersResolver)[]>, TypeParent, TContext>; - followingUsers?: FollowingUsersResolver)[]>, TypeParent, Context>; + followingUsers?: FollowingUsersResolver)[]>, TypeParent, TContext>; - posts?: PostsResolver)[]>, TypeParent, Context>; + posts?: PostsResolver)[]>, TypeParent, TContext>; } - export type IdResolver, Parent = AdminUser, Context = {}> = Resolver; - export type UsernameResolver, Parent = AdminUser, Context = {}> = Resolver; - export type RoleResolver, Parent = AdminUser, Context = {}> = Resolver; - export type LikedPostsResolver)[]>, Parent = AdminUser, Context = {}> = Resolver; - export type FollowerUsersResolver)[]>, Parent = AdminUser, Context = {}> = Resolver; + export type IdResolver, Parent = AdminUser, TContext = {}> = Resolver; + export type UsernameResolver, Parent = AdminUser, TContext = {}> = Resolver; + export type RoleResolver, Parent = AdminUser, TContext = {}> = Resolver; + export type LikedPostsResolver)[]>, Parent = AdminUser, TContext = {}> = Resolver; + export type FollowerUsersResolver)[]>, Parent = AdminUser, TContext = {}> = Resolver; export interface FollowerUsersArgs { skip?: Maybe; @@ -333,7 +333,7 @@ export namespace AdminUserResolvers { } - export type FollowingUsersResolver)[]>, Parent = AdminUser, Context = {}> = Resolver; + export type FollowingUsersResolver)[]>, Parent = AdminUser, TContext = {}> = Resolver; export interface FollowingUsersArgs { skip?: Maybe; @@ -342,7 +342,7 @@ export namespace AdminUserResolvers { } - export type PostsResolver)[]>, Parent = AdminUser, Context = {}> = Resolver; + export type PostsResolver)[]>, Parent = AdminUser, TContext = {}> = Resolver; export interface PostsArgs { skip?: Maybe; @@ -350,32 +350,32 @@ export namespace AdminUserResolvers { limit?: Maybe; } - + } export namespace WriterUserResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver, TypeParent, Context>; + id?: IdResolver, TypeParent, TContext>; - username?: UsernameResolver, TypeParent, Context>; + username?: UsernameResolver, TypeParent, TContext>; - role?: RoleResolver, TypeParent, Context>; + role?: RoleResolver, TypeParent, TContext>; - likedPosts?: LikedPostsResolver)[]>, TypeParent, Context>; + likedPosts?: LikedPostsResolver)[]>, TypeParent, TContext>; - followerUsers?: FollowerUsersResolver)[]>, TypeParent, Context>; + followerUsers?: FollowerUsersResolver)[]>, TypeParent, TContext>; - followingUsers?: FollowingUsersResolver)[]>, TypeParent, Context>; + followingUsers?: FollowingUsersResolver)[]>, TypeParent, TContext>; - posts?: PostsResolver)[]>, TypeParent, Context>; + posts?: PostsResolver)[]>, TypeParent, TContext>; } - export type IdResolver, Parent = WriterUser, Context = {}> = Resolver; - export type UsernameResolver, Parent = WriterUser, Context = {}> = Resolver; - export type RoleResolver, Parent = WriterUser, Context = {}> = Resolver; - export type LikedPostsResolver)[]>, Parent = WriterUser, Context = {}> = Resolver; + export type IdResolver, Parent = WriterUser, TContext = {}> = Resolver; + export type UsernameResolver, Parent = WriterUser, TContext = {}> = Resolver; + export type RoleResolver, Parent = WriterUser, TContext = {}> = Resolver; + export type LikedPostsResolver)[]>, Parent = WriterUser, TContext = {}> = Resolver; export interface LikedPostsArgs { skip?: Maybe; @@ -384,7 +384,7 @@ export namespace WriterUserResolvers { } - export type FollowerUsersResolver)[]>, Parent = WriterUser, Context = {}> = Resolver; + export type FollowerUsersResolver)[]>, Parent = WriterUser, TContext = {}> = Resolver; export interface FollowerUsersArgs { skip?: Maybe; @@ -393,7 +393,7 @@ export namespace WriterUserResolvers { } - export type FollowingUsersResolver)[]>, Parent = WriterUser, Context = {}> = Resolver; + export type FollowingUsersResolver)[]>, Parent = WriterUser, TContext = {}> = Resolver; export interface FollowingUsersArgs { skip?: Maybe; @@ -402,7 +402,7 @@ export namespace WriterUserResolvers { } - export type PostsResolver)[]>, Parent = WriterUser, Context = {}> = Resolver; + export type PostsResolver)[]>, Parent = WriterUser, TContext = {}> = Resolver; export interface PostsArgs { skip?: Maybe; @@ -410,30 +410,30 @@ export namespace WriterUserResolvers { limit?: Maybe; } - + } export namespace ReaderUserResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver, TypeParent, Context>; + id?: IdResolver, TypeParent, TContext>; - username?: UsernameResolver, TypeParent, Context>; + username?: UsernameResolver, TypeParent, TContext>; - role?: RoleResolver, TypeParent, Context>; + role?: RoleResolver, TypeParent, TContext>; - likedPosts?: LikedPostsResolver)[]>, TypeParent, Context>; + likedPosts?: LikedPostsResolver)[]>, TypeParent, TContext>; - followerUsers?: FollowerUsersResolver)[]>, TypeParent, Context>; + followerUsers?: FollowerUsersResolver)[]>, TypeParent, TContext>; - followingUsers?: FollowingUsersResolver)[]>, TypeParent, Context>; + followingUsers?: FollowingUsersResolver)[]>, TypeParent, TContext>; } - export type IdResolver, Parent = ReaderUser, Context = {}> = Resolver; - export type UsernameResolver, Parent = ReaderUser, Context = {}> = Resolver; - export type RoleResolver, Parent = ReaderUser, Context = {}> = Resolver; - export type LikedPostsResolver)[]>, Parent = ReaderUser, Context = {}> = Resolver; + export type IdResolver, Parent = ReaderUser, TContext = {}> = Resolver; + export type UsernameResolver, Parent = ReaderUser, TContext = {}> = Resolver; + export type RoleResolver, Parent = ReaderUser, TContext = {}> = Resolver; + export type LikedPostsResolver)[]>, Parent = ReaderUser, TContext = {}> = Resolver; export interface LikedPostsArgs { skip?: Maybe; @@ -442,7 +442,7 @@ export namespace ReaderUserResolvers { } - export type FollowerUsersResolver)[]>, Parent = ReaderUser, Context = {}> = Resolver; + export type FollowerUsersResolver)[]>, Parent = ReaderUser, TContext = {}> = Resolver; export interface FollowerUsersArgs { skip?: Maybe; @@ -451,7 +451,7 @@ export namespace ReaderUserResolvers { } - export type FollowingUsersResolver)[]>, Parent = ReaderUser, Context = {}> = Resolver; + export type FollowingUsersResolver)[]>, Parent = ReaderUser, TContext = {}> = Resolver; export interface FollowingUsersArgs { skip?: Maybe; @@ -459,7 +459,7 @@ export namespace ReaderUserResolvers { limit?: Maybe; } - + } @@ -467,7 +467,7 @@ export namespace UserResolvers { export interface Resolvers { __resolveType: ResolveType; } - export type ResolveType = TypeResolveFn; + export type ResolveType = TypeResolveFn; } @@ -542,16 +542,16 @@ export interface DateScalarConfig extends GraphQLScalarTypeConfig { name: 'Date' } -export interface IResolvers { - Post?: PostResolvers.Resolvers; - AdminUser?: AdminUserResolvers.Resolvers; - WriterUser?: WriterUserResolvers.Resolvers; - ReaderUser?: ReaderUserResolvers.Resolvers; - User?: UserResolvers.Resolvers; +export type IResolvers = { + Post?: PostResolvers.Resolvers; + AdminUser?: AdminUserResolvers.Resolvers; + WriterUser?: WriterUserResolvers.Resolvers; + ReaderUser?: ReaderUserResolvers.Resolvers; + User?: UserResolvers.Resolvers; Date?: GraphQLScalarType; -} +} & { [typeName: string] : never }; -export interface IDirectiveResolvers { +export type IDirectiveResolvers = { union?: UnionDirectiveResolver; abstractEntity?: AbstractEntityDirectiveResolver; entity?: EntityDirectiveResolver; @@ -563,4 +563,4 @@ export interface IDirectiveResolvers { skip?: SkipDirectiveResolver; include?: IncludeDirectiveResolver; deprecated?: DeprecatedDirectiveResolver; -} \ No newline at end of file +} & { [directiveName: string] : never }; diff --git a/dev-test/test-schema/resolvers-root.ts b/dev-test/test-schema/resolvers-root.ts index 3552f07258c..61edb77a40b 100644 --- a/dev-test/test-schema/resolvers-root.ts +++ b/dev-test/test-schema/resolvers-root.ts @@ -57,35 +57,35 @@ import { GraphQLResolveInfo } from 'graphql'; -export type Resolver = ( +export type Resolver = ( parent: Parent, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Promise | Result; -export interface ISubscriptionResolverObject { +export interface ISubscriptionResolverObject { subscribe( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): AsyncIterator | Promise>; resolve?( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): R | Result | Promise; } -export type SubscriptionResolver = - | ((...args: any[]) => ISubscriptionResolverObject) - | ISubscriptionResolverObject; +export type SubscriptionResolver = + | ((...args: any[]) => ISubscriptionResolverObject) + | ISubscriptionResolverObject; -export type TypeResolveFn = ( +export type TypeResolveFn = ( parent: Parent, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Maybe; @@ -101,51 +101,51 @@ export type DirectiveResolverFn = ( export namespace QueryRootResolvers { - export interface Resolvers { + export interface Resolvers { - allUsers?: AllUsersResolver<(Maybe)[], TypeParent, Context>; + allUsers?: AllUsersResolver<(Maybe)[], TypeParent, TContext>; - userById?: UserByIdResolver, TypeParent, Context>; + userById?: UserByIdResolver, TypeParent, TContext>; /** Generates a new answer for the guessing game */ - answer?: AnswerResolver; + answer?: AnswerResolver; } - export type AllUsersResolver)[], Parent = {}, Context = {}> = Resolver; - export type UserByIdResolver, Parent = {}, Context = {}> = Resolver; + export type AllUsersResolver)[], Parent = {}, TContext = {}> = Resolver; + export type UserByIdResolver, Parent = {}, TContext = {}> = Resolver; export interface UserByIdArgs { id: number; } - export type AnswerResolver = Resolver; + export type AnswerResolver = Resolver; } export namespace UserResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver; + id?: IdResolver; - name?: NameResolver; + name?: NameResolver; - email?: EmailResolver; + email?: EmailResolver; } - export type IdResolver = Resolver; - export type NameResolver = Resolver; - export type EmailResolver = Resolver; + export type IdResolver = Resolver; + export type NameResolver = Resolver; + export type EmailResolver = Resolver; } export namespace SubscriptionRootResolvers { - export interface Resolvers { + export interface Resolvers { - newUser?: NewUserResolver, TypeParent, Context>; + newUser?: NewUserResolver, TypeParent, TContext>; } - export type NewUserResolver, Parent = {}, Context = {}> = SubscriptionResolver; + export type NewUserResolver, Parent = {}, TContext = {}> = SubscriptionResolver; } @@ -173,14 +173,14 @@ export interface DeprecatedDirectiveArgs { -export interface IResolvers { - QueryRoot?: QueryRootResolvers.Resolvers; - User?: UserResolvers.Resolvers; - SubscriptionRoot?: SubscriptionRootResolvers.Resolvers; -} +export type IResolvers = { + QueryRoot?: QueryRootResolvers.Resolvers; + User?: UserResolvers.Resolvers; + SubscriptionRoot?: SubscriptionRootResolvers.Resolvers; +} & { [typeName: string] : never }; -export interface IDirectiveResolvers { +export type IDirectiveResolvers = { skip?: SkipDirectiveResolver; include?: IncludeDirectiveResolver; deprecated?: DeprecatedDirectiveResolver; -} \ No newline at end of file +} & { [directiveName: string] : never }; diff --git a/dev-test/test-schema/resolvers-types.ts b/dev-test/test-schema/resolvers-types.ts index 2f60664894f..513f347a991 100644 --- a/dev-test/test-schema/resolvers-types.ts +++ b/dev-test/test-schema/resolvers-types.ts @@ -51,35 +51,35 @@ import { GraphQLResolveInfo } from 'graphql'; -export type Resolver = ( +export type Resolver = ( parent: Parent, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Promise | Result; -export interface ISubscriptionResolverObject { +export interface ISubscriptionResolverObject { subscribe( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): AsyncIterator | Promise>; resolve?( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): R | Result | Promise; } -export type SubscriptionResolver = - | ((...args: any[]) => ISubscriptionResolverObject) - | ISubscriptionResolverObject; +export type SubscriptionResolver = + | ((...args: any[]) => ISubscriptionResolverObject) + | ISubscriptionResolverObject; -export type TypeResolveFn = ( +export type TypeResolveFn = ( parent: Parent, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Maybe; @@ -95,41 +95,41 @@ export type DirectiveResolverFn = ( export namespace QueryResolvers { - export interface Resolvers { + export interface Resolvers { - allUsers?: AllUsersResolver<(Maybe)[], TypeParent, Context>; + allUsers?: AllUsersResolver<(Maybe)[], TypeParent, TContext>; - userById?: UserByIdResolver, TypeParent, Context>; + userById?: UserByIdResolver, TypeParent, TContext>; - answer?: AnswerResolver; + answer?: AnswerResolver; } - export type AllUsersResolver)[], Parent = {}, Context = {}> = Resolver; - export type UserByIdResolver, Parent = {}, Context = {}> = Resolver; + export type AllUsersResolver)[], Parent = {}, TContext = {}> = Resolver; + export type UserByIdResolver, Parent = {}, TContext = {}> = Resolver; export interface UserByIdArgs { id: number; } - export type AnswerResolver = Resolver; + export type AnswerResolver = Resolver; } export namespace UserResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver; + id?: IdResolver; - name?: NameResolver; + name?: NameResolver; - email?: EmailResolver; + email?: EmailResolver; } - export type IdResolver = Resolver; - export type NameResolver = Resolver; - export type EmailResolver = Resolver; + export type IdResolver = Resolver; + export type NameResolver = Resolver; + export type EmailResolver = Resolver; } @@ -157,13 +157,13 @@ export interface DeprecatedDirectiveArgs { -export interface IResolvers { - Query?: QueryResolvers.Resolvers; - User?: UserResolvers.Resolvers; -} +export type IResolvers = { + Query?: QueryResolvers.Resolvers; + User?: UserResolvers.Resolvers; +} & { [typeName: string] : never }; -export interface IDirectiveResolvers { +export type IDirectiveResolvers = { skip?: SkipDirectiveResolver; include?: IncludeDirectiveResolver; deprecated?: DeprecatedDirectiveResolver; -} \ No newline at end of file +} & { [directiveName: string] : never }; diff --git a/dev-test/test-schema/typings.ts b/dev-test/test-schema/typings.ts index d204797c0c4..444611508a0 100644 --- a/dev-test/test-schema/typings.ts +++ b/dev-test/test-schema/typings.ts @@ -49,35 +49,35 @@ import { GraphQLResolveInfo } from 'graphql'; -export type Resolver = ( +export type Resolver = ( parent: Parent, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Promise | Result; -export interface ISubscriptionResolverObject { +export interface ISubscriptionResolverObject { subscribe( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): AsyncIterator | Promise>; resolve?( parent: P, args: Args, - context: Context, + context: TContext, info: GraphQLResolveInfo ): R | Result | Promise; } -export type SubscriptionResolver = - | ((...args: any[]) => ISubscriptionResolverObject) - | ISubscriptionResolverObject; +export type SubscriptionResolver = + | ((...args: any[]) => ISubscriptionResolverObject) + | ISubscriptionResolverObject; -export type TypeResolveFn = ( +export type TypeResolveFn = ( parent: Parent, - context: Context, + context: TContext, info: GraphQLResolveInfo ) => Maybe; @@ -93,38 +93,38 @@ export type DirectiveResolverFn = ( export namespace QueryResolvers { - export interface Resolvers { + export interface Resolvers { - allUsers?: AllUsersResolver<(Maybe)[], TypeParent, Context>; + allUsers?: AllUsersResolver<(Maybe)[], TypeParent, TContext>; - userById?: UserByIdResolver, TypeParent, Context>; + userById?: UserByIdResolver, TypeParent, TContext>; } - export type AllUsersResolver)[], Parent = {}, Context = {}> = Resolver; - export type UserByIdResolver, Parent = {}, Context = {}> = Resolver; + export type AllUsersResolver)[], Parent = {}, TContext = {}> = Resolver; + export type UserByIdResolver, Parent = {}, TContext = {}> = Resolver; export interface UserByIdArgs { id: number; } - + } export namespace UserResolvers { - export interface Resolvers { + export interface Resolvers { - id?: IdResolver; + id?: IdResolver; - name?: NameResolver; + name?: NameResolver; - email?: EmailResolver; + email?: EmailResolver; } - export type IdResolver = Resolver; - export type NameResolver = Resolver; - export type EmailResolver = Resolver; + export type IdResolver = Resolver; + export type NameResolver = Resolver; + export type EmailResolver = Resolver; } @@ -152,13 +152,13 @@ export interface DeprecatedDirectiveArgs { -export interface IResolvers { - Query?: QueryResolvers.Resolvers; - User?: UserResolvers.Resolvers; -} +export type IResolvers = { + Query?: QueryResolvers.Resolvers; + User?: UserResolvers.Resolvers; +} & { [typeName: string] : never }; -export interface IDirectiveResolvers { +export type IDirectiveResolvers = { skip?: SkipDirectiveResolver; include?: IncludeDirectiveResolver; deprecated?: DeprecatedDirectiveResolver; -} \ No newline at end of file +} & { [directiveName: string] : never }; diff --git a/packages/plugins/typescript-client/tests/typescript-client.spec.ts b/packages/plugins/typescript-client/tests/typescript-client.spec.ts index 0659e27efd4..207cef0f8ec 100644 --- a/packages/plugins/typescript-client/tests/typescript-client.spec.ts +++ b/packages/plugins/typescript-client/tests/typescript-client.spec.ts @@ -1018,4 +1018,51 @@ describe('TypeScript Client', () => { } `); }); + + it('avoid duplicates - each type name should be unique', async () => { + const testSchema = makeExecutableSchema({ + typeDefs: gql` + type DeleteMutation { + deleted: Boolean! + } + + type UpdateMutation { + updated: Boolean! + } + + union MessageMutationType = DeleteMutation | UpdateMutation + + type Query { + dummy: String + } + + type Mutation { + mutation(message: String!, type: String!): MessageMutationType! + } + ` + }); + const query = gql` + mutation SubmitMessage($message: String!) { + mutation(message: $message) { + ... on DeleteMutation { + deleted + } + ... on UpdateMutation { + updated + } + } + } + `; + + const content = await plugin( + testSchema, + [{ filePath: '', content: query }], + {}, + { + outputFile: 'graphql.ts' + } + ); + + expect(content.match(/type Mutation\b/g)).toHaveLength(1); + }); }); diff --git a/packages/utils/plugins-helpers/src/flatten-types.ts b/packages/utils/plugins-helpers/src/flatten-types.ts index 834db9a14e9..87e665dff1e 100644 --- a/packages/utils/plugins-helpers/src/flatten-types.ts +++ b/packages/utils/plugins-helpers/src/flatten-types.ts @@ -40,8 +40,10 @@ export interface FlattenModel { hasTypename: boolean; } +const operationTypes = ['query', 'mutation', 'subscription'].map(name => pascalCase(name)); + export const handleNameDuplications = (name: string, existing: FlattenModel[]): string => { - if (existing.find(model => model.modelType === name)) { + if (operationTypes.includes(name) || existing.find(model => model.modelType === name)) { return handleNameDuplications('_' + name, existing); }