Closed kamilbrenk closed 1 year ago
Hi. I am trying to use type generated by the ACF field (clickable in admin) in my GraphQL field. This is what the field registration looks like:
add_action( 'graphql_register_types', function() { register_graphql_field( 'RootQuery', 'mapRouteLayerBy', array( 'type' => 'Map_Details_Layers_Route', 'args' => array( 'layer_id' => array( 'type' => 'String', 'description' => 'Map layer id', ) ), 'resolve' => function ($root, $args, $context, $info) { if (empty($args['layer_id'])) { return null; } $map_layers = get_field('layers', 4003); if (empty($map_layers)) { return null; } return $map_layers[0]; // this layer returned data of type Map_Details_Layers_Route }, )); });
As expected, a new field appears in the GraphiQL IDE:
Unfortunately, as you can see, the data beyond fieldGroupName is missing.
FYI: the data it passes in the resolve function:
Definition of type Map_Details_Layers_Route:
Why is it that despite providing the correct data in the resolve function, it does not match the Map_Details_Layers_Route type? How to fix this?
FYI: The problem was passing content from the ACF field with formatting. The solution is the following fix:
$map_layers = get_field('layers', 4003, false);
Hi. I am trying to use type generated by the ACF field (clickable in admin) in my GraphQL field. This is what the field registration looks like:
As expected, a new field appears in the GraphiQL IDE:
Unfortunately, as you can see, the data beyond fieldGroupName is missing.
FYI: the data it passes in the resolve function:
Definition of type Map_Details_Layers_Route:
Why is it that despite providing the correct data in the resolve function, it does not match the Map_Details_Layers_Route type? How to fix this?