graphql-net icon indicating copy to clipboard operation
graphql-net copied to clipboard

Document schema.AddScalar(), AddEnum

Open markhepburn opened this issue 8 years ago • 2 comments

I'd submit a PR but I'm unclear exactly how it's used, myself :)

GraphQLSchema defines a method AddScalar, which has something to do with validating and translating scalar types.

It's used in the tests to add a DateTime with year/month/day components, but I'm a bit unclear where these components come from, since the translation is only in one direction.

Without it, tests that query a model with a DateTime field will fail; for eg, comment out the AddScalar line in EntityFrameworkExecutionTests.CreateDefaultContext(), or alternatively in EntityFrameworkExecutionTests.AddAllFields() add a query on account (in this test Account is defined via AddAllFields(), but without the DateTime scalar added to the schema):

gql.ExecuteQuery("{ account(id:1) { id } }");

markhepburn avatar Oct 06 '16 23:10 markhepburn

AddScalar only has one translation because it only ever needs to do one. We treat scalars as values that we could either receive as input to a query or return as output in a result set (which cannot have their own selection set, see: https://facebook.github.io/graphql/#sec-Scalars).

Our result sets are entirely in-memory, not serialized. This is so that you can pass them off to whatever serialization library you want (likely Newtonsoft.Json, but we're flexible). Given that, we have no need to provide a translation from a scalar type back to a string type.

However, since we parse the input query and can accept an arbitrary scalar, we have to be able to build that scalar up from components we understand (ints, floats, strings, etc.).

I intended to write some additional documentation this weekend (related to #46), so while I'm doing that I can add real documentation for these features as well.

chkimes avatar Oct 07 '16 03:10 chkimes

Aah, I see thanks, so it's in the query-parsing direction? That makes sense.

Why does it raise an exception though when you execute a query, if you're not parsing (or serialising) that field? (Obviously I haven't dug that deep into that bit of the code sorry, I was just curious at this point)

markhepburn avatar Oct 10 '16 00:10 markhepburn