zoukankan      html  css  js  c++  java
  • [GraphQL] Query GraphQL Interface Types in GraphQL Playground

    Interfaces are similar to Unions in that they provide a mechanism for dealing with different types of data. However, an interface is more suited for data types that include many of the same fields. In this lesson, we will query different types of pets.

    To follow along with these queries, go to the Pet Library GraphQL Playground.

    Interface:

    # Write your query or mutation here
    query {
      totalPets,
      availablePets,
      checkedOutPets,
      allAvailablePets {
        __typename,
        ...PetDetail,
        # only related to CAT
        ... on Cat {
          sleepAmount
        },
        # only related to Rabbit
        ... on Rabbit {
          favoriteFood,
          floppy
        },
        # only related to Stingray
        ... on  Stingray {
          fast
        }
      }
    }
    
    fragment PetDetail on Pet {
      name,
      weight,
      status,
      photo {
        thumb
      }
    }

    Data return:

    {
      "data": {
        "totalPets": 25,
        "availablePets": 23,
        "checkedOutPets": 2,
        "allAvailablePets": [
          {
            "__typename": "Cat",
            "name": "Biscuit",
            "weight": 10.2,
            "status": null,
            "photo": {
              "thumb": "https://www.catis.life/placeholder/200"
            },
            "sleepAmount": 21
          },
         ...
    
    }
  • 相关阅读:
    兼容IE678浏览器的html5标签的几个方案
    CommonJS和AMD/CMD
    axios的使用
    自己写表单校验插件
    表单校验
    JS打开新窗口的2种方式
    mac 上使用移动硬盘
    Boostrap
    Web.config详解
    DataTable
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11384598.html
Copyright © 2011-2022 走看看