-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(visitor-plugin-common): avoid reading from null values (#9709)
* fix(visitor-plugin-common): avoid reading from null values * Add e2e test
- Loading branch information
Showing
6 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-codegen/visitor-plugin-common': patch | ||
--- | ||
|
||
Avoid reading from null values when selection sets only contain fragments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const MY_QUERY = /* GraphQL */ ` | ||
fragment CartLine on CartLine { | ||
id | ||
quantity | ||
} | ||
query Test { | ||
cart { | ||
lines { | ||
nodes { | ||
...CartLine | ||
} | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export type Maybe<T> = T | null; | ||
export type InputMaybe<T> = Maybe<T>; | ||
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | ||
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> }; | ||
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> }; | ||
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never }; | ||
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; | ||
/** All built-in and custom scalars, mapped to their actual values */ | ||
export type Scalars = { | ||
ID: { input: string; output: string }; | ||
String: { input: string; output: string }; | ||
Boolean: { input: boolean; output: boolean }; | ||
Int: { input: number; output: number }; | ||
Float: { input: number; output: number }; | ||
}; | ||
|
||
export type BaseCartLine = { | ||
id: Scalars['String']['output']; | ||
quantity: Scalars['Int']['output']; | ||
}; | ||
|
||
export type BaseCartLineConnection = { | ||
id: Scalars['String']['output']; | ||
nodes: Array<BaseCartLine>; | ||
}; | ||
|
||
export type Cart = { | ||
id: Scalars['String']['output']; | ||
lines: BaseCartLineConnection; | ||
}; | ||
|
||
export type CartLine = BaseCartLine & { | ||
id: Scalars['String']['output']; | ||
quantity: Scalars['Int']['output']; | ||
}; | ||
|
||
export type ComponentizableCartLine = BaseCartLine & { | ||
id: Scalars['String']['output']; | ||
quantity: Scalars['Int']['output']; | ||
}; | ||
|
||
export type QueryRoot = { | ||
cart?: Maybe<Cart>; | ||
}; | ||
|
||
export type CartLineFragment = { id: string; quantity: number }; | ||
|
||
export type TestQueryVariables = Exact<{ [key: string]: never }>; | ||
|
||
export type TestQuery = { cart?: { lines: { nodes: Array<{ id: string; quantity: number }> } } | null }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
schema { | ||
query: QueryRoot | ||
} | ||
|
||
interface BaseCartLine { | ||
id: String! | ||
quantity: Int! | ||
} | ||
|
||
type BaseCartLineConnection { | ||
id: String! | ||
nodes: [BaseCartLine!]! | ||
} | ||
|
||
type Cart { | ||
id: String! | ||
lines: BaseCartLineConnection! | ||
} | ||
|
||
type CartLine implements BaseCartLine { | ||
id: String! | ||
quantity: Int! | ||
} | ||
|
||
type ComponentizableCartLine implements BaseCartLine { | ||
id: String! | ||
quantity: Int! | ||
} | ||
|
||
type QueryRoot { | ||
cart: Cart | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters