當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Tyr.graphql方法代碼示例

本文整理匯總了TypeScript中tyranid.Tyr.graphql方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Tyr.graphql方法的具體用法?TypeScript Tyr.graphql怎麽用?TypeScript Tyr.graphql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tyranid.Tyr的用法示例。


在下文中一共展示了Tyr.graphql方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

  fn: async (t: TestContext) => {
    const ted = await Tyr.byName.user.findOne({ query: { name: 'ted' } });
    if (!ted) {
      throw new Error(`No ted found`);
    }

    const query = `
      query getUserById($id: [ID]) {
        user(_id: $id) {
          status {
            name
          }
        }
      }
    `;

    const result = await Tyr.graphql({
      query,
      variables: {
        id: [ted.$id]
      }
    });

    const expected = {
      data: {
        user: {
          status: {
            name: 'Active'
          }
        }
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:35,代碼來源:enum-collection.ts

示例2: async

  fn: async (t: TestContext) => {
    const query = `
      query userNameQuery {
        users {
          name
          teamIds {
            name,
            organizationId {
              name
            }
          }
        }
      }
    `;

    const result = await Tyr.graphql({ query });

    const expected = {
      data: {
        users: [
          {
            name: 'ben',
            teamIds: [
              {
                name: 'burritoMakers',
                organizationId: {
                  name: 'Chipotle'
                }
              },
              {
                name: 'chipotleMarketing',
                organizationId: {
                  name: 'Chipotle'
                }
              }
            ]
          },
          {
            name: 'ted',
            teamIds: [
              {
                name: 'cavaEngineers',
                organizationId: {
                  name: 'Cava'
                }
              }
            ]
          },
          {
            name: 'noTeams',
            teamIds: []
          }
        ]
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:58,代碼來源:array-populated.ts

示例3: async

  fn: async (t: TestContext) => {
    const burritoMakers = await Tyr.byName.team.findOne({
      query: { name: 'burritoMakers' }
    });
    if (!burritoMakers) {
      throw new Error(`No burrito`);
    }

    const query = `
      query userNameQuery {
        users {
          name
          teamIds(_id: "${burritoMakers.$id}") {
            name,
            organizationId {
              name
            }
          }
        }
      }
    `;

    const result = await Tyr.graphql({ query });

    const expected = {
      data: {
        users: [
          {
            name: 'ben',
            teamIds: [
              {
                name: 'burritoMakers',
                organizationId: {
                  name: 'Chipotle'
                }
              }
            ]
          },
          {
            name: 'ted',
            teamIds: []
          },
          {
            name: 'noTeams',
            teamIds: []
          }
        ]
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:52,代碼來源:sub-document-parameters.ts

示例4: async

  fn: async (t: TestContext) => {
    const ted = await Tyr.byName.user.findOne({ query: { name: 'ted' } });
    if (!ted) {
      throw new Error(`No ted`);
    }

    const query = `
      query getUserById($id: [ID]) {
        user(_id: $id) {
          name
          teamIds {
            name,
            organizationId {
              name
            }
          }
        }
      }
    `;

    const result = await Tyr.graphql({
      query,
      variables: {
        id: [ted.$id]
      }
    });

    const expected = {
      data: {
        user: {
          name: 'ted',
          teamIds: [
            {
              name: 'cavaEngineers',
              organizationId: {
                name: 'Cava'
              }
            }
          ]
        }
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:45,代碼來源:variables.ts

示例5: async

  fn: async (t: TestContext) => {
    const query = `
      query userNameQuery {
        users {
          name
          organizationId {
            name
          }
        }
      }
    `;

    const result = await Tyr.graphql({ query });

    const expected = {
      data: {
        users: [
          {
            name: 'ben',
            organizationId: {
              name: 'Chipotle'
            }
          },
          {
            name: 'ted',
            organizationId: {
              name: 'Cava'
            }
          },
          {
            name: 'noTeams',
            organizationId: {
              name: 'Chipotle'
            }
          }
        ]
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:41,代碼來源:single-populated.ts

示例6: async

  fn: async (t: TestContext) => {
    const query = `
      query userNameQuery {
        users(name: "ben") {
          computed
        }
      }
    `;

    const result = await Tyr.graphql({ query });

    const expected = {
      data: {
        users: [
          {
            computed: 'Hello ben from a computed property!'
          }
        ]
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:23,代碼來源:computed-property-projection.ts

示例7: async

  fn: async (t: TestContext) => {
    const query = `
      query userQuery {
        user(name: "ben") {
          ...userProps
        }
      }

      fragment userProps on user {
        name
        teamIds {
          name
        }
      }
    `;

    const result = await Tyr.graphql({ query });

    const expected = {
      data: {
        user: {
          name: 'ben',
          teamIds: [
            {
              name: 'burritoMakers'
            },
            {
              name: 'chipotleMarketing'
            }
          ]
        }
      }
    };

    t.deepEqual<ExecutionResult>(result, expected);
  }
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:36,代碼來源:fragments.ts


注:本文中的tyranid.Tyr.graphql方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。