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

BETWEEN Type not working, MetaArray value needs to accept Array values? #14

Open
a-zog opened this issue Jan 22, 2020 · 3 comments
Open

Comments

@a-zog
Copy link

a-zog commented Jan 22, 2020

Hi, thank you for the great work you've did !

I would like to have a query that returns all the "Events" that are happening during the next weekend.

This is the query I've crafted:

query getEvents(
  $perpage: Int!
  $weekend_start: String!
  $weekend_end: String!
  $after: String
) {
  this_weekend: events(
    first: $perpage
    after: $after
    where: {
      metaQuery: {
        relation: OR
        metaArray: [
          {
            key: "date_start"
            compare: BETWEEN
            value: [$weekend_start, $weekend_end]
          }
          {
            key: "date_end"
            compare: BETWEEN
            value: [$weekend_start, $weekend_end]
          }
        ]
      }
    }
  ) {
    nodes {
      __typename
      date
      title
    }
  }
}

I've encountered an "Internal server error" issue.
I suspect that is due to the fact that the value property doesn't accept array values.

Would you please help me with this?

@a-zog a-zog changed the title BETWEEN Type not working, MetaArray value needs to accept Array values BETWEEN Type not working, MetaArray value needs to accept Array values? Jan 22, 2020
@jasonbahl
Copy link
Contributor

@a-zog I'm thinking instead of BETWEEN you might want BEFORE and AFTER?

Something like:

metaArray: [
          {
            key: "date_start"
            compare: AFTER
            value: $weekend_start
          }
          {
            key: "date_end"
            compare: BEFORE
            value: $weekend_end
          }
        ]

Or something along those lines?

@jasonbahl
Copy link
Contributor

It does seem that this meta query plugin should accept one or more values for the value input though, since WP_Query allows it. 🤔

@a-zog
Copy link
Author

a-zog commented Jan 23, 2020

It does seem that this meta query plugin should accept one or more values for the value input though, since WP_Query allows it. 🤔

I've suspected that because I've found this code in the MetaArray fields definitions.

$type_registry->register_input_type( $type_name . 'MetaArray', [
    'fields' => [
       ...
        'value'   => [
            'type'        => 'String',
            'description' => __( 'Custom field value', 'wp-graphql' ),
        ],
       ....
    ]
] );

I can either implement BETWEEN or a combination of OR / AND (example here) so I'm sure that all the cases are covered. None of these would unfortunately work.

$args => array(
        'relation' => 'OR',
        array(
            'relation' => 'AND',
            array(
                'key' => 'event_date_start',
                'value' => $weekend_start,
                'compare' => '>='
            ),
            array(
                'key' => 'event_date_end',
                'value' => $weekend_start,
                'compare' => '<='
            )
        ),
        array(
            'relation' => 'AND',
            array(
                'key' => 'event_date_start',
                'value' => $weekend_end,
                'compare' => '>='
            ),
            array(
                'key' => 'event_date_end',
                'value' => $weekend_end,
                'compare' => '<='
            )
        ),
    )
);

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