1- import  type  {  ObjMap  }  from  '../jsutils/ObjMap' ; 
1+ import  type  {  ObjMap ,   ReadOnlyObjMap  }  from  '../jsutils/ObjMap' ; 
22import  type  {  Maybe  }  from  '../jsutils/Maybe' ; 
33import  {  keyMap  }  from  '../jsutils/keyMap' ; 
44import  {  inspect  }  from  '../jsutils/inspect' ; 
@@ -15,7 +15,7 @@ import { Kind } from '../language/kinds';
1515import  {  print  }  from  '../language/printer' ; 
1616
1717import  type  {  GraphQLSchema  }  from  '../type/schema' ; 
18- import  type  {  GraphQLField  }  from  '../type/definition' ; 
18+ import  type  {  GraphQLInputType ,   GraphQLField  }  from  '../type/definition' ; 
1919import  type  {  GraphQLDirective  }  from  '../type/directives' ; 
2020import  {  isInputType ,  isNonNullType  }  from  '../type/definition' ; 
2121
@@ -26,9 +26,20 @@ import {
2626  coerceDefaultValue , 
2727}  from  '../utilities/coerceInputValue' ; 
2828
29- type  CoercedVariableValues  = 
30-   |  {  errors : ReadonlyArray < GraphQLError > ;  coerced ?: never  } 
31-   |  {  coerced : {  [ variable : string ] : unknown  } ;  errors ?: never  } ; 
29+ export  interface  VariableValues  { 
30+   readonly  sources : ReadOnlyObjMap < VariableValueSource > ; 
31+   readonly  coerced : ReadOnlyObjMap < unknown > ; 
32+ } 
33+ 
34+ interface  VariableValueSource  { 
35+   readonly  variable : VariableDefinitionNode ; 
36+   readonly  type : GraphQLInputType ; 
37+   readonly  value : unknown ; 
38+ } 
39+ 
40+ type  VariableValuesOrErrors  = 
41+   |  {  variableValues : VariableValues ;  errors ?: never  } 
42+   |  {  errors : ReadonlyArray < GraphQLError > ;  variableValues ?: never  } ; 
3243
3344/** 
3445 * Prepares an object map of variableValues of the correct type based on the 
@@ -46,11 +57,11 @@ export function getVariableValues(
4657  varDefNodes : ReadonlyArray < VariableDefinitionNode > , 
4758  inputs : {  readonly  [ variable : string ] : unknown  } , 
4859  options ?: {  maxErrors ?: number  } , 
49- ) : CoercedVariableValues  { 
50-   const  errors  =  [ ] ; 
60+ ) : VariableValuesOrErrors  { 
61+   const  errors :  Array < GraphQLError >  =  [ ] ; 
5162  const  maxErrors  =  options ?. maxErrors ; 
5263  try  { 
53-     const  coerced  =  coerceVariableValues ( 
64+     const  variableValues  =  coerceVariableValues ( 
5465      schema , 
5566      varDefNodes , 
5667      inputs , 
@@ -65,7 +76,7 @@ export function getVariableValues(
6576    ) ; 
6677
6778    if  ( errors . length  ===  0 )  { 
68-       return  {  coerced  } ; 
79+       return  {  variableValues  } ; 
6980    } 
7081  }  catch  ( error )  { 
7182    errors . push ( error ) ; 
@@ -79,8 +90,9 @@ function coerceVariableValues(
7990  varDefNodes : ReadonlyArray < VariableDefinitionNode > , 
8091  inputs : {  readonly  [ variable : string ] : unknown  } , 
8192  onError : ( error : GraphQLError )  =>  void , 
82- ) : {  [ variable : string ] : unknown  }  { 
83-   const  coercedValues : {  [ variable : string ] : unknown  }  =  { } ; 
93+ ) : VariableValues  { 
94+   const  sources : ObjMap < VariableValueSource >  =  Object . create ( null ) ; 
95+   const  coerced : ObjMap < unknown >  =  Object . create ( null ) ; 
8496  for  ( const  varDefNode  of  varDefNodes )  { 
8597    const  varName  =  varDefNode . variable . name . value ; 
8698    const  varType  =  typeFromAST ( schema ,  varDefNode . type ) ; 
@@ -98,11 +110,14 @@ function coerceVariableValues(
98110    } 
99111
100112    if  ( ! hasOwnProperty ( inputs ,  varName ) )  { 
101-       if  ( varDefNode . defaultValue )  { 
102-         coercedValues [ varName ]  =  coerceInputLiteral ( 
103-           varDefNode . defaultValue , 
104-           varType , 
105-         ) ; 
113+       const  defaultValue  =  varDefNode . defaultValue ; 
114+       if  ( defaultValue )  { 
115+         sources [ varName ]  =  { 
116+           variable : varDefNode , 
117+           type : varType , 
118+           value : undefined , 
119+         } ; 
120+         coerced [ varName ]  =  coerceInputLiteral ( defaultValue ,  varType ) ; 
106121      }  else  if  ( isNonNullType ( varType ) )  { 
107122        onError ( 
108123          new  GraphQLError ( 
@@ -125,7 +140,8 @@ function coerceVariableValues(
125140      continue ; 
126141    } 
127142
128-     coercedValues [ varName ]  =  coerceInputValue ( 
143+     sources [ varName ]  =  {  variable : varDefNode ,  type : varType ,  value } ; 
144+     coerced [ varName ]  =  coerceInputValue ( 
129145      value , 
130146      varType , 
131147      ( path ,  invalidValue ,  error )  =>  { 
@@ -148,7 +164,7 @@ function coerceVariableValues(
148164    ) ; 
149165  } 
150166
151-   return  coercedValues ; 
167+   return  {  sources ,  coerced  } ; 
152168} 
153169
154170/** 
@@ -164,7 +180,7 @@ function coerceVariableValues(
164180export  function  getArgumentValues ( 
165181  def : GraphQLField < unknown ,  unknown >  |  GraphQLDirective , 
166182  node : FieldNode  |  DirectiveNode , 
167-   variableValues ?: Maybe < ObjMap < unknown > > , 
183+   variableValues ?: Maybe < VariableValues > , 
168184) : {  [ argument : string ] : unknown  }  { 
169185  const  coercedValues : {  [ argument : string ] : unknown  }  =  { } ; 
170186
@@ -199,7 +215,7 @@ export function getArgumentValues(
199215      const  variableName  =  valueNode . name . value ; 
200216      if  ( 
201217        variableValues  ==  null  || 
202-         ! hasOwnProperty ( variableValues ,   variableName ) 
218+         variableValues . coerced [ variableName ]   ===   undefined 
203219      )  { 
204220        if  ( argDef . defaultValue )  { 
205221          coercedValues [ name ]  =  coerceDefaultValue ( 
@@ -215,7 +231,7 @@ export function getArgumentValues(
215231        } 
216232        continue ; 
217233      } 
218-       isNull  =  variableValues [ variableName ]  ==  null ; 
234+       isNull  =  variableValues . coerced [ variableName ]  ==  null ; 
219235    } 
220236
221237    if  ( isNull  &&  isNonNullType ( argType ) )  { 
@@ -256,7 +272,7 @@ export function getArgumentValues(
256272export  function  getDirectiveValues ( 
257273  directiveDef : GraphQLDirective , 
258274  node : {  readonly  directives ?: ReadonlyArray < DirectiveNode >  } , 
259-   variableValues ?: Maybe < ObjMap < unknown > > , 
275+   variableValues ?: Maybe < VariableValues > , 
260276) : undefined  |  {  [ argument : string ] : unknown  }  { 
261277  // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') 
262278  const  directiveNode  =  node . directives ?. find ( 
0 commit comments