Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nested complex fields #20

Closed
judas-christ opened this issue Feb 15, 2024 · 3 comments
Closed

Support for nested complex fields #20

judas-christ opened this issue Feb 15, 2024 · 3 comments

Comments

@judas-christ
Copy link
Contributor

judas-christ commented Feb 15, 2024

I'm trying out this plugin and have a page with a complex field for sections. One of the sections is a gallery which is a complex field itself with a variable number of images in it. The setup looks like this:

WpGraphQLCrbContainer::register(
        Container::make('post_meta', 'Sections')
            ->where('post_type', '=', 'page')
            ->add_fields(
                array(
                    Field::make('complex', 'crb_sections')
                        ->set_visible_in_rest_api(true)
                        ->add_fields(
                            'gallery',
                            array(
                                Field::make('complex', 'gallery')
                                    ->add_fields(
                                        'gallery_images',
                                        array(
                                            Field::make('image', 'gallery_image')
                                        )
                                    )
                            )
                        )
                        ->add_fields(
                            'prose',
                            array(
                                Field::make('rich_text', 'content'),
                            )
                        ),
                )
            )
    );
}

and a query like this:

query NewQuery {
  page(id: 9, idType: DATABASE_ID) {
    crbSections {
      content
      gallery {
        gallery_image {
          srcSet
        }
      }
    }
  }
}

And I get this error in the response:

{
  "errors": [
    {
      "debugMessage": "array_map(): Argument #2 ($array) must be of type array, null given",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "page",
        "crbSections"
      ]
    }
  ],
  "data": {
    "page": {
      "crbSections": null
    }
  },
  "extensions": {
    "debug": [],
    "queryAnalyzer": {
      "keys": "284225654371f49f4cd084d8c41b5f5d62fea543433d98f0dc5557994cce662a graphql:Query operation:NewQuery cG9zdDo5",
      "keysLength": 106,
      "keysCount": 4,
      "skippedKeys": "",
      "skippedKeysSize": 0,
      "skippedKeysCount": 0,
      "skippedTypes": []
    }
  }
}

Everything works using the REST API and with GraphQL if I remove the gallery section so I suspect the problem is with the nested complex fields. Have I done something obviously wrong? Has anyone run into something similar?

Update: so it seems the nested complex fields work as long as I do not add any other type of section. So on a page with only galleries, the query works, but if I add a prose section the query immediately fails, even if I don't include the content field in the query.

Update 2: I get the same issue when I use the built in media_gallery field type. Works fine by itself, but adding another type of field causes the error.

@matepaiva
Copy link
Owner

Thank you @judas-christ for your contribution! A new version was released: 0.0.7.

Do you think we should add something about this in the README?

@judas-christ
Copy link
Contributor Author

Awesome @matepaiva . I'm not sure it needs a special mention now that it should work as expected.

@matepaiva
Copy link
Owner

ok, so i will close this issue as finished. thank you again for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants