4

During her brilliant presentation about scaling GraphQL, Leanne Shapton showed some best practices.

One of the most attractive for me was the custom scalar type for HTML structure. On the video it's [10:16]

She proposed using the custom HTML instead of simple String. enter image description here

I wish you could show your implementation of this scalar or how do you handle these cases as I'm using only String for any HTML structure which doesn't seem to be a perfect way.

I'm asking not for creating scalar types or general information what is it scalar type and so on. Wondering if someone else has HTML handling already and does someone has any working solutions

1 Answer 1

2

At a pure GraphQL level, the only thing you can (and must) do is include a definition for the scalar type:

scalar HTML

Once you done that, you can use it as a type as shown in the slide you cite. In queries and results it will appear as some sort of scalar (string or numeric) value.

Different server and client libraries have different ways of dealing with this; there may be a uniform way to map a specific GraphQL scalar type to a native-language object. In graphql-js, a GraphQLScalarType object takes parseValue and serialize functions to convert between the two representations, for example. If you're just using a custom scalar type as a tagged string these can be very simple functions.

Sign up to request clarification or add additional context in comments.

1 Comment

of course, David, thank you for the answer but creating custom scalars wasn't an issue. What I'm asking is real-world implementations of this case which is quite widespread but still no modular solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.