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

Registered Connections should apply an Interface to the "from" Type signifying it has said connection #2027

Open
jasonbahl opened this issue Jul 20, 2021 · 3 comments
Labels
Component: Connections Issues related to connections Component: Interfaces Type: Enhancement New feature or request

Comments

@jasonbahl
Copy link
Collaborator

When registering a connection, it would be nice if the Type that the connection is coming from implemented an Interface to signify/document that the Type supports said connection.

Let's take Post Type and Taxonomy connections as an example.

We (as developers with prior WordPress experience) know that Posts have Categories and Tags, but we don't know what other Post Types (ContentNodes) have Category/Tag connections. And we also don't inherently know what other Post Types have connections with other Taxonomies. We can browse the Schema a bit to find out have to really know what we're looking for.

If each Post Type that had connections with Term Nodes implemented an Interface such as NodeWithTermNodeConnection we could search this type in a tool such as GraphiQL and find all Types that have connections with Terms.

Let's look at this in SDL to better grasp the idea:

Interface NodeWithTermNodeConnection {
  terms: TermNodeConnection
}

Interface ContentNodeWithTagConnection implements NodeWithTermNodeConnection {
  terms: TermNodeConnection
  tags: TagConnection
}

Interface ContentNodeWithSomeOtherTaxonomyConnection implements NodeWithTermNodeConnection {
  terms: TermNodeConnection
  someOtherTaxonomy: SomeOtherTaxonomyConnection
}

Then the Post Types that are connected with the Taxonomies could implement Interfaces like so:

type Post implements NodeWithTagConnection
type CustomPostType implements NodeWithSomeOtherTaxonomyConnection
type CustomTypeWithNoTaxonomyConnections

Then we could query like so:

{
  post: nodeByUri(uri:"/path-to-post") {
    ...NodeByUri
  }
  customType: nodeByUri(uri:"/path-to-custom-type") {
    ...NodeByUri
  }
  customTypeWithNoTaxonomyConnections: nodeByUri(uri:"/path-to-type-with-no-taxonomy-connection") {
    ...NodeByUri
  }
}

fragment NodeByUri on UniformResourceIdentifiable {
  __typename
  uri
  ...Tags
  ...CustomTaxonomies
  ...AllTerms
}

fragment Tags on NodeWithTagConnection {
  tags {
    nodes {
       __typename
    }
  }
}

fragment CustomTaxonomies on NodeWithCustomTaxonomyConnection {
  customTaxonomies {
    nodes {
      __typename
    }
  }
}

fragment AllTerms on NodeWithTermsConnection {
  terms {
    nodes {
      __typename
    }
  }
}

This would be a valid query. We could query nodes from the root and specify that we want the connected fields only if the node being returned had the connection we were interested in.

We would get a payload like so:

{
  "post": {
    "__typename": "Post",
    "uri": "/path-to-post",
    "tags": {
      "nodes":[ 
        {
          "__typaname": "Tag"     
        }
      ]
    },
    "allTerms": {
      "nodes":[ 
        {
          "__typaname": "Tag"     
        }
      ]
    }
  },
  "customType": {
    "__typename": "CustomType",
    "uri": "/path-to-custom-type",
    "customTaxonomies": {
      "nodes":[ 
        {
          "__typaname": "CustomTaxonomy"     
        }
      ]
    },
    "allTerms": {
      "nodes":[ 
        {
          "__typaname": "CustomTaxonomy"     
        }
      ]
    }
  },
  "customTypeWithNoTaxonomyConnections": {
    "__typename": "CustomTypeWithNoTaxonomyConnections",
    "uri": "/path-to-type-with-no-taxonomy-connection"
  }
}
@stale
Copy link

stale bot commented Aug 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Sep 2, 2022

This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue.

@stale stale bot closed this as completed Sep 2, 2022
@justlevine justlevine reopened this Sep 2, 2022
@stale stale bot removed the stale label Sep 2, 2022
@stale
Copy link

stale bot commented Dec 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale? May need to be revalidated due to prolonged inactivity label Dec 1, 2022
@jasonbahl jasonbahl added not stale Short-circuits stalebot. USE SPARINGLY and removed Stale? May need to be revalidated due to prolonged inactivity labels Dec 1, 2022
@justlevine justlevine removed the not stale Short-circuits stalebot. USE SPARINGLY label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Connections Issues related to connections Component: Interfaces Type: Enhancement New feature or request
Projects
Status: 🗺 Planned
Development

No branches or pull requests

2 participants