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

Snippets don't identify themselves #386

Open
jams2 opened this issue Apr 10, 2024 · 0 comments
Open

Snippets don't identify themselves #386

jams2 opened this issue Apr 10, 2024 · 0 comments

Comments

@jams2
Copy link
Contributor

jams2 commented Apr 10, 2024

SnippetObjectType is implemented as a union of a project's registered snippet models. Unless the snippet classes themselves implement a field that can discriminate the specific type of a snippet instance, it can be difficult to determine which type of snippet you have in a client.

For example, if using a stream field with SnippetChooserBlock, I might query it as follows:

query MyPages {
  pages(id: 28) {
    title
    ... on MyPage {
      streamFieldContent {
        ... on SnippetChooserBlock {
          id
          blockType
          snippet {
            ... on FooSnippet {
              fooField
            }
            ... on BarSnippet {
              barField
            }
          }
        }
      }
    }
  }
}

The issue then is determining exactly which snippet type I get in response. I could query __typename on SnippetObjectType, but this won't work in environments where introspection queries are forbidden.

To get around this in my project we've added our own snippet interface type, which has a snippetType field, which returns the snippet class name. Something similar would be a valuable addition to grapple.

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

1 participant