Interface

Description

Represents a list of named fields and their arguments. GraphQL objects can then implement an interface, which guarantees that they will contain the specified fields.

Absinthe Macro

interface

Examples

In an Absinthe schema, defining the interface and mapping results to the associated GraphQL type:

​ @desc ​"​​A named object"​
​ interface ​:named​ ​do​
​  field ​:name​, ​:string​
​  ​# Other fields to be implemented​
​  resolve_type ​fn​
​  %Item{}, _ ->
​  ​:item​
​  _, _ ->
​  nil
​  ​end​
​ ​end​

An object type implementing the interface:

​ @desc ​"​​An item"​
​ object ​:item​ ​do​
» interfaces [​:named​]
​  field ​:name​, ​

Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.