@@ -35,30 +35,36 @@ public function __construct(string $name, TypeInterface $type, array $arguments,
3535 $ config = [
3636 'name ' => $ name ,
3737 'type ' => $ type ,
38- 'args ' => $ arguments
38+ 'args ' => array_map ( function ( array $ item ) { return $ item [ ' type ' ]; }, $ arguments)
3939 ];
4040
4141 $ config ['resolve ' ] = function ($ source , array $ args , ResolveInfo $ info ) use ($ resolve , $ arguments ) {
4242 $ toPassArgs = [];
43- foreach ($ arguments as $ name => $ type ) {
44- // FIXME: this is not ok for default values! We need to take the default value of the reflected argument.
45- $ val = $ args [$ name ] ?? null ;
43+ foreach ($ arguments as $ name => $ arr ) {
44+ $ type = $ arr ['type ' ];
45+ if (isset ($ args [$ name ])) {
46+ $ val = $ args [$ name ];
4647
47- $ type = $ this ->stripNonNullType ($ type );
48- if ($ type instanceof ListType) {
49- $ subtype = $ this ->stripNonNullType ($ type ->getItemType ());
50- $ val = array_map (function ($ item ) use ($ subtype ) {
51- if ($ subtype instanceof DateTimeType) {
52- return new \DateTimeImmutable ($ item );
53- } elseif ($ subtype ->getKind () === TypeMap::KIND_INPUT_OBJECT ) {
54- return $ this ->hydrator ->hydrate ($ item , $ subtype );
55- };
56- return $ item ;
57- }, $ val );
58- } elseif ($ type instanceof DateTimeType) {
59- $ val = new \DateTimeImmutable ($ val );
60- } elseif ($ type ->getKind () === TypeMap::KIND_INPUT_OBJECT ) {
61- $ val = $ this ->hydrator ->hydrate ($ val , $ type );
48+ $ type = $ this ->stripNonNullType ($ type );
49+ if ($ type instanceof ListType) {
50+ $ subtype = $ this ->stripNonNullType ($ type ->getItemType ());
51+ $ val = array_map (function ($ item ) use ($ subtype ) {
52+ if ($ subtype instanceof DateTimeType) {
53+ return new \DateTimeImmutable ($ item );
54+ } elseif ($ subtype ->getKind () === TypeMap::KIND_INPUT_OBJECT ) {
55+ return $ this ->hydrator ->hydrate ($ item , $ subtype );
56+ };
57+ return $ item ;
58+ }, $ val );
59+ } elseif ($ type instanceof DateTimeType) {
60+ $ val = new \DateTimeImmutable ($ val );
61+ } elseif ($ type ->getKind () === TypeMap::KIND_INPUT_OBJECT ) {
62+ $ val = $ this ->hydrator ->hydrate ($ val , $ type );
63+ }
64+ } elseif (isset ($ arr ['default ' ])) {
65+ $ val = $ arr ['default ' ];
66+ } else {
67+ throw new GraphQLException ("Expected argument ' $ name' was not provided. " );
6268 }
6369
6470 $ toPassArgs [] = $ val ;
0 commit comments