Skip to content

Commit a6d12c7

Browse files
committed
Update docs with examples of DSLSchema.__call__ shortcut syntax
1 parent 12e07ac commit a6d12c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/advanced/dsl_module.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,16 @@ The above example will generate the following request::
328328
}
329329
}
330330

331+
Alternatively, you can use the DSL shortcut syntax to create a fragment by
332+
passing the string ``"fragment"`` directly to the :meth:`__call__ <gql.dsl.DSLSchema.__call__>` method.
333+
When using the shortcut, you must also provide the fragment name via the ``name`` parameter::
334+
335+
name_and_appearances = (
336+
ds("fragment", "NameAndAppearances")
337+
.on(ds.Character)
338+
.select(ds.Character.name, ds.Character.appearsIn)
339+
)
340+
331341
Inline Fragments
332342
^^^^^^^^^^^^^^^^
333343

@@ -373,6 +383,14 @@ this can be written in a concise manner::
373383
DSLInlineFragment().on(ds.Human).select(ds.Human.homePlanet)
374384
)
375385

386+
Alternatively, you can use the DSL shortcut syntax to create an inline fragment by
387+
passing the string ``"..."`` directly to the :meth:`__call__ <gql.dsl.DSLSchema.__call__>` method::
388+
389+
query_with_inline_fragment = ds.Query.hero.args(episode=6).select(
390+
ds.Character.name,
391+
ds("...")
392+
)
393+
376394
Meta-fields
377395
^^^^^^^^^^^
378396

@@ -384,6 +402,15 @@ you can use the :class:`DSLMetaField <gql.dsl.DSLMetaField>` class::
384402
DSLMetaField("__typename")
385403
)
386404

405+
Alternatively, you can use the DSL shortcut syntax to create the same meta-field by
406+
passing the ``"__typename"`` string directly to the :meth:`__call__ <gql.dsl.DSLSchema.__call__>` method::
407+
408+
query = ds.Query.hero.select(
409+
ds.Character.name,
410+
ds("__typename")
411+
)
412+
413+
387414
Directives
388415
^^^^^^^^^^
389416

0 commit comments

Comments
 (0)