Skip to content

Implement consistent filter arg across connections #1385

Description

@seagyn

This is a post v1 discussion which started on Slack: https://wp-graphql.slack.com/archives/C3NM1M291/p1594650031121400

The idea is #1384 is nice to have in core but it's very WP like which makes it harder for none WP developers to gain the correct context and the different ways to filter. The long term plan would be to add a filtering system into core that is consistent no matter you're querying against. There are plenty of edge cases so it's worth having a deep and mostly long discussion about it before any implementation takes place.

Initial ideas

Filtering by taxonomy

Array of category slugs:

{
  posts({ 
    filter: {
     categoryIn: [{ id: "category-b", idType: SLUG }, { id: "category-b", idType: SLUG }]
    }
  })
}

Single category:

{
  posts({ 
    filter: {
      categoryId: { id: "category-b", idType: SLUG }
    }
  })
}

Complex category query:

{
  posts({ 
    filter: {
      AND: [
        categoryIn: [{ id: "category-b", idType: SLUG }],
        categoryNotIn: [{ id: "category-a", idType: SLUG }]
      ]
    }
  })
}

By post information

A query you would probably never make but could:

{
  posts({ 
    filter: {
      AND: [
        idIn: [{id: 21, idType: DATABASE_ID}],
        titleNotIn: [ "some title" ],
        titleLike: "something",
        titleNotLike: "something else",
        contentContains: "some string",
      ]
    }
  })
}

Mixed queries with mixed relations

{
  posts({ 
    filter: {
      OR: [
        titleLike: "something",
        AND: [
          categoryIn: [{ id: "category-b", idType: SLUG }],
          idIn: [{id: 21, idType: DATABASE_ID}, {id: "/path", idType: URI}]
        ],
      ]
    }
  })
}

The idea here is that you can quickly build up filter queries without requiring knowledge of how WP_Query works.

Metadata

Metadata

Assignees

Labels

compat: breaking changeThis is a breaking change to existing functionalitycomponent: connectionsRelating to GraphQL Connectionscomponent: inputRelating to GraphQL Input Typeseffort: highMore than a weekimpact: highUnblocks new use cases, substantial improvement to existing feature, fixes a major bugneeds: discussionRequires a discussion to proceedtype: enhancementImprovements to existing functionality

Type

No type
No fields configured for issues without a type.

Projects

Status
🗺 Planned

Relationships

None yet

Development

No branches or pull requests

Issue actions