Wp-graphql: Register new connections

Created on 26 Oct 2017  路  3Comments  路  Source: wp-graphql/wp-graphql

I have two CPTs (Companies and Addresses) and I'm storing the metadata for each CPT in custom tables instead of the wp_postmeta table simply because meta queries are expensive.
The two custom tables are linked with a foreign key.

Is there a way to register a connection for the two CPTs so I can do a query like below:

{
  companyBy(slug: "company-slug") {
    companyId
    content
    excerpt
    addresses (city: "new-york") {
      edges {
        node {
          addressId
          streetName1
          streeName2
          city
        }
      }
    }
  }
}
Needs Discussion question

Most helpful comment

@cr101 I鈥檝e been thinking a lot about what registering new connections might look like without _too_ much custom code and I think I have a pretty good idea on how to approach it.

I鈥檒l try and play with the idea over the next few days and see what I can come up with.

For now, if you _really_ need something you can check out how the existing connections are implemented and implement something similar for your specific connections.

All 3 comments

@cr101 I鈥檝e been thinking a lot about what registering new connections might look like without _too_ much custom code and I think I have a pretty good idea on how to approach it.

I鈥檒l try and play with the idea over the next few days and see what I can come up with.

For now, if you _really_ need something you can check out how the existing connections are implemented and implement something similar for your specific connections.

@jasonbahl this kind of goes with #246 and #327. Do you want to keep this issue with that, or maybe create a different one?

I'll close this and track in #327

Was this page helpful?
0 / 5 - 0 ratings