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

Incorrect GraphQL Where schemas generated for Relation fields #6399

Open
slavanossar opened this issue May 17, 2024 · 0 comments
Open

Incorrect GraphQL Where schemas generated for Relation fields #6399

slavanossar opened this issue May 17, 2024 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@slavanossar
Copy link
Contributor

slavanossar commented May 17, 2024

Link to reproduction

No response

Describe the Bug

When a collection has a queryable document field of the form

{
  doc: {
    relationTo: 'pages'
    value: /* ... */
  }
}

The generated GraphQL schema for the where input is incorrect, with relationTo being used as an operator:

input Page_where {
  doc: Page_doc_Relation
}

input Page_doc_Relation {
  relationTo: Page_Doc_RelationTo
  value: JSON
}

enum Page_Doc_RelationTo {
  pages
}

This is invalid, as relationTo is not included in validOperators or in the operatorMap, meaning the query is completely ignored by parseParams and buildSearchParam.

To Reproduce

You can see this on the PayloadPreference_where input in the generated schema, but I first encountered it when using @payloadcms/plugin-search. After setting up the search plugin, observe the generated Search_where inputs:

input Search_where {
  title: Search_title_operator
  priority: Search_priority_operator
  doc: Search_doc_Relation
  updatedAt: Search_updatedAt_operator
  createdAt: Search_createdAt_operator
  id: Search_id_operator
  AND: [Search_where_and]
  OR: [Search_where_or]
}

input Search_doc_Relation {
  relationTo: Search_doc_Relation_RelationTo
  value: JSON
}

enum Search_doc_Relation_RelationTo {
  collectionA
  collectionB
  collectionC
}

which means that this is a "valid" query but doesn't filter by collectionA:

query GetSearches {
  Searches(
    where: { doc: { relationTo: collectionA } }
  ) {
    docs {
      id
      title
      doc {
        relationTo
      }
    }
  }
}

In reality it should probably be something like

input Search_where {
  title: Search_title_operator
  priority: Search_priority_operator
  doc: Search_doc_Relation
  updatedAt: Search_updatedAt_operator
  createdAt: Search_createdAt_operator
  id: Search_id_operator
  AND: [Search_where_and]
  OR: [Search_where_or]
}

input Search_doc_Relation {
  relationTo: Search_doc_Relation_RelationTo_operator
  value: JSON
}

input Search_doc_Relation_RelationTo_operator {
  equals: Search_doc_Relation_RelationTo
  not_equals: Search_doc_Relation_RelationTo
  like: Search_doc_Relation_RelationTo
  contains: Search_doc_Relation_RelationTo
  in: [Search_doc_Relation_RelationTo]
  not_in: [Search_doc_Relation_RelationTo]
  all: [Search_doc_Relation_RelationTo]
  exists: Boolean
}

enum Search_doc_Relation_RelationTo {
  collectionA
  collectionB
  collectionC
}

Potentially being caused by something in buildWhereInputType?

Payload Version

2.18.1

Adapters and Plugins

db-mongodb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant