GraphQL fragment matcher

I have been working on utilizing the dynamic zone component using graphql fragments. I have been working off the tutorial and after having hit roadblock after roadblock (which forced me to get a better understanding of fragments and unions as im a noob!) i still havent managed to get things working.

Since i couldnt get things to work, i took a test run off the repo provided (which is genius btw!) which works as intended after some package updates.

However, in my own project my fragmentTypes.json seems to render very differently and is subsequently trowing me an error “Cannot read property ‘types’ of undefined”.

Excerpt of the repo’s fragmentTypes.json:

{
  "__schema": {
    "types": [
      {
        "kind": "UNION",
        "name": "Morph",
        "possibleTypes": [
          {
            "name": "UsersPermissionsMe"
          },
          {
            "name": "UsersPermissionsMeRole"
          }, 

          Etcetera

      {
        "kind": "UNION",
        "name": "PagesPageZoneDynamicZone",
        "possibleTypes": [
          {
            "name": "ComponentPostQuote"
          },
          {
            "name": "ComponentPostImage"
          },
          {
            "name": "ComponentPostRichText"
          }
        ]
      }

And the fragmentTypes.json rendered in my own project (notice how it is missing the " __schema" & “types” decleration:

{
  "possibleTypes": {
    "CollectionPageZoneDynamicZone": [
      "ComponentDynamicImageAndText",
      "ComponentDynamicImageSlider",
      "ComponentDynamicRichText"
    ],
    "GqlfragmentPageZoneDynamicZone": [
      "ComponentDynamicImageAndText",
      "ComponentDynamicImageSlider",
      "ComponentDynamicRichText"
    ],
    "Morph": [
      "UsersPermissionsMe",
      "UsersPermissionsMeRole",
      "UsersPermissionsLoginPayload",
      "UserPermissionsPasswordPayload",
      "Collection",
      Etcetera

In my reading up on the topic, i found that since apollo ^3.0 there has been a change in decleration and use of fragments, maybe that has something to do with it?
V2 fragment docs
^V3 fragment docs

Any help would be greatly appreciated!

I made some progress:

Instead of running the “generate” build script, i ran: “yarn -graphql-codegen” and it seemed to render a working possibleTypes schema!

TIme to fiddle in the frontend now :crazy_face:

Back at this… Been having a really weird bug where the collection ID is not being fetched in the dom (i think?)

So, started from a fresh boilerplate repo building back the codegen add-ons… Now cant get a properly rendered fragmentTypes.json again…

bashes head against a keyboard

Small update after lots of trial and error:

Used old graphql codegen packages, as per versions used in the tutorial repo; getting a proper rendered possibleTypes.json again.
So i definitely have issues declaring the proper config file for apollo 3.0

Hey Sven, having the exact same issue my end - I want to use the latest version of the packages and apollo client 3 - will report back if I get anywhere.

Edit: So with the latest versions of both apollo client and codegen-cli/introspection/fragment-matcher I get the correct schema output if I just add the following to my codegen.yml.
config: apolloClientVersion: 2

I’m going to test this as part of my build using it to hydrate from NuxtServerInit inside of Vuex. Will post another update if I see anything other than the Unions and __schema required for DynamicZones

Hey,

That seems like a very usable solution, thanks for the update!
Curious as to how the native apollo 3 schema will respond to Strapi V4 though.
Definetly worth checking in again then. Will have a fiddle myself when its released.