diff --git a/docs/Linq2GraphQL.Docs/Pages/GettingStarted.razor b/docs/Linq2GraphQL.Docs/Pages/GettingStarted.razor index 1b7cf889..5fd91c05 100644 --- a/docs/Linq2GraphQL.Docs/Pages/GettingStarted.razor +++ b/docs/Linq2GraphQL.Docs/Pages/GettingStarted.razor @@ -88,8 +88,10 @@ parameters.
Include, optional and repeatable. Scalar fields are always fetched.
- Related objects and lists of scalars are fetched only when you include them, to any depth. A field
+ Include, optional and repeatable. The object you select is always
+ fetched with its scalar fields. Related objects and lists of scalars are fetched only when you
+ include them, to any depth; the object at the end of an include path gets its scalar fields, the
+ ones it passes through don't (see selecting fields). A field
that takes arguments is a method. C# doesn't allow named arguments out of position inside a lambda
that becomes an expression tree, so pass them by position: f.CharacterConnection(null, 5)
sends first: 5 to that nested field.
diff --git a/docs/Linq2GraphQL.Docs/Pages/SelectingFields.razor b/docs/Linq2GraphQL.Docs/Pages/SelectingFields.razor
index 02d3fb59..3ea8c399 100644
--- a/docs/Linq2GraphQL.Docs/Pages/SelectingFields.razor
+++ b/docs/Linq2GraphQL.Docs/Pages/SelectingFields.razor
@@ -41,6 +41,44 @@
+
+ An Include path names the object you want; the fields it passes through are only the way
+ there. The object at the end of the path is fetched with all its scalar fields, and the objects along
+ the way get only what is needed to reach it:
+
+ Each film gets its scalar fields because it is the end of Select(e => e.Films), and each
+ character gets its scalar fields because it is the end of the Include path.
+ characterConnection is in the middle of the path, so none of its own fields, such as
+ totalCount, are requested. To fetch an object in the middle as well, include it on its own:
+
+ A field that wasn't requested keeps its C# default value in the generated type: null
+ for references and nullable types, but 0, false or Guid.Empty for
+ non-nullable value types. In those cases you can't tell a field that was left out from one the server
+ really returned as zero. If you depend on which fields are present, project instead: a projection
+ requests exactly the fields it reads.
+
+ Why it works this way: a GraphQL query asks only for what it names, and a path names its last field.
+ The levels in between are often just structure, such as connections and nodes lists, with
+ little worth fetching. With this rule you can always add a level by including it, while the opposite
+ rule (fetch every level) would need a way to leave levels out, and LINQ has no syntax for that. It is
+ also how projections work: you get what you name.
+
+ Coming from Entity Framework Core? There is no ThenInclude; continue the path with
+ Select instead: .Include(c => c.Orders).ThenInclude(o => o.Lines) is written
+ .Include(c => c.Orders.Select(o => o.Lines)). Unlike EF, that fetches the scalar fields of
+ the lines only, not of the orders they are reached through; add .Include(c => c.Orders)
+ if you want both.
+
Project into an anonymous type with the fields you want:
@@ -118,6 +156,24 @@