-
Notifications
You must be signed in to change notification settings - Fork 5
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
Graphql Error on association field with custom post type or taxonomy if it has multiple types. #4
Comments
@benada002 thank you for the contribution. I will have a look at this tonight, ok? |
Great contribution! I will merge and release a new version. |
I will wait for another PR and then I will release a new version. I let you know here. |
Sounds great. Since diff --git a/src/Field.php b/src/Field.php
index b1a9bf6..57b6669 100644
--- a/src/Field.php
+++ b/src/Field.php
@@ -189,22 +189,11 @@ private function getTypeFromAssociation()
if ($object instanceof Post) {
$graphql_single_name = \get_post_type_object($object->post_type)->graphql_single_name;
- if ($graphql_single_name === 'post') {
- return 'Post';
- }
-
return ucfirst($graphql_single_name);
}
if ($object instanceof Term) {
$taxonomy_name = \get_taxonomy($object->taxonomyName)->graphql_single_name;
- if ($taxonomy_name === 'category') {
- return 'Category';
- }
-
- if ($taxonomy_name === 'tag') {
- return 'Tag';
- }
return ucfirst($taxonomy_name);
} What do you think about it? Should I raise another PR? Or do you want to keep it like it is? |
If you could open another PR, it would be awesome :) |
Ok, I'll do it in the afternoon. |
Thank you! |
Hello, I already fixed it, so I will update the release and close this issue. Thank you again! |
New version available:
Thank you for your contribution! |
I've a association field with a custom subtype and multiple types, like this:
If the
graphql_single_name
option (from the post type or taxonomy) not starts with an uppercase letter, it results in a graphql error:Type loader is expected to return type "materialCategory", but it returned "MaterialCategory"
.I took a look at it and saw that
register_graphql_union_type
function, triggers aprepare_type
function that usesucfirst
for the type name. The following fix works for me.The text was updated successfully, but these errors were encountered: