I'm working on a 10.2 solution with JSS & NextJS using the GraphQL (edge) endpoint. I already noticed this endpoint is sometimes quite different compared to others and now I would like to extend it. We are also using SXA and I wanted to use a treelist with tokens in the datasource so I created a custom field for that - which is pretty easy to do.

Our problem now is that the data from that field is fetched as string and not as a Multilist field (which would give us an item array). And as GraphQL is used to fetch all data that is an issue...

My first attempt was adding my field in the config (identical as the Treelist) to /sitecore/api/GraphQL/defaults/content/fieldTypeMappings/standardTypeMapping in the config as this is mentioned in the edgeContent schema provider. That doesn't work.

I did find 2 ways I can extend the schema:

  • Apparently all fields are added to a list and attached to a GraphType in Sitecore.Services.GraphQL.EdgeSchema.TemplateGeneration.FieldMapping.DefaultFieldTypeFactoryStore. I can create my own version of this factory and inject instead - this works but somehow I don't think this is the correct way to extend this as the class doesn't seem to be made to be extended.
  • I was able (as a test) to extend existing GraphType's (eg the ImageFieldGraphType) with extra properties by creating a SchemaExtender. This feels like the more official way to extend things as it is also mentioned in the SC documentation (although not for 10.2). But.. this way I managed to extend existing types, but I don't know how to tell the schema that my "Tokened Treelist" is actually just a MultilistGraphType with such an extender.

So, my question is: how can I use my custom field in the GraphQL schema as Multilist? Can this be done with a SchemaExtender, and if so - how? Should I overwrite the FieldTypeFactoryStore?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.