• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript graphql.graphql函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中graphql.graphql函数的典型用法代码示例。如果您正苦于以下问题:TypeScript graphql函数的具体用法?TypeScript graphql怎么用?TypeScript graphql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了graphql函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: it

 it('a query returns an empty array', async () => {
     const query = `
         query {
             Post {
                 results {
                     id,
                     title,
                     body,
                     published,
                     post_date
                 }
             }
         }
     `;
     const result = await graphql(schema, query);
     expect(result.data!.Post.results).to.deep.equal([]);
 });
开发者ID:RevFramework,项目名称:rev-framework,代码行数:17,代码来源:reading_scalar_data.tests.ts


示例2: async

async () => {
    const mergedSchema = mergeSchemas({
      schemas: [
        // pull in an executable schema just so mergeSchema doesn't complain
        // about not finding default types (e.g. ID)
        propertySchema,
        testSchemaWithInterfaceResolvers
      ],
      resolvers
    });
    const query = `{ user { id name } }`;
    const response = await graphql(mergedSchema, query);
    expect(response.errors.length).to.equal(1);
    expect(response.errors[0].message).to.equal('Cannot return null for ' +
      'non-nullable field User.id.');
    expect(response.errors[0].path).to.deep.equal(['user', 'id']);
  });
开发者ID:apollostack,项目名称:graphql-tools,代码行数:17,代码来源:testAlternateMergeSchemas.ts


示例3: it

 it('does not return "results" and "meta" objects at lower levels', async () => {
     const query = `
         query {
             Post {
                 results {
                     id,
                     title,
                     comments {
                         id,
                         comment
                     }
                 }
                 meta {
                     limit
                     offset
                     totalCount
                 }
             }
         }
     `;
     const result = await graphql(schema, query);
     expect(result.data!.Post).to.deep.equal({
         results: [
             {
                 id: 1, title: 'RevJS v1.0.0 Released!',
                 comments: [
                     { id: 1, comment: 'I totally agree'},
                     { id: 2, comment: 'Sweet!' }
                 ]
             },
             {
                 id: 2, title: 'JavaScript is Awesome',
                 comments: []
             },
             {
                 id: 3, title: 'Ruby Sucks',
                 comments: []
             }
         ],
         meta: {
             limit: 20,
             offset: 0,
             totalCount: 3
         }
     });
 });
开发者ID:RevFramework,项目名称:rev-framework,代码行数:46,代码来源:query_object.tests.ts


示例4: it

 it('I can get Posts by their id', async () => {
     const query = `
         query {
             Post(where: {id : 2}) {
                 results {
                     id,
                     title
                 }
             }
         }
     `;
     const result = await graphql(schema, query);
     expect(result.data!.Post.results).to.deep.equal([{
         id: 2,
         title: 'JavaScript is Awesome'
     }]);
 });
开发者ID:RevFramework,项目名称:rev-framework,代码行数:17,代码来源:filtering_data.tests.ts


示例5: Observable

 return new Observable(observer => {
   const { query, operationName, variables } = operation;
   const { graphqlContext } = operation.getContext();
   graphql(
     schema,
     print(query),
     null,
     graphqlContext,
     variables,
     operationName,
   )
     .then(result => {
       observer.next(result);
       observer.complete();
     })
     .catch(observer.error.bind(observer));
 });
开发者ID:sventschui,项目名称:graphql-tools,代码行数:17,代码来源:testingSchemas.ts


示例6: it

  it('logs any Promise reject errors', done => {
    const shorthand = `
      type RootQuery {
        just_a_field: Int
      }
      type RootMutation {
        species(name: String): String
        stuff: String
      }
      schema {
        query: RootQuery
        mutation: RootMutation
      }
    `;
    const resolve = {
      RootMutation: {
        species: () => {
          return new Promise((_, reject) => {
            reject(new Error('oops!'));
          });
        },
        stuff: () => {
          return new Promise((_, reject) => {
            reject(new Error('oh noes!'));
          });
        },
      },
    };
    const logger = new Logger();
    const jsSchema = makeExecutableSchema({
      typeDefs: shorthand,
      resolvers: resolve,
      logger,
    });

    const testQuery = 'mutation { species, stuff }';
    const expected0 = 'Error in resolver RootMutation.species\noops!';
    const expected1 = 'Error in resolver RootMutation.stuff\noh noes!';
    graphql(jsSchema, testQuery).then(() => {
      assert.equal(logger.errors.length, 2);
      assert.equal(logger.errors[0].message, expected0);
      assert.equal(logger.errors[1].message, expected1);
      done();
    });
  });
开发者ID:sventschui,项目名称:graphql-tools,代码行数:45,代码来源:testLogger.ts


示例7: it

      it('fragments on non-compatible sub schema types', async () => {
        const result = await graphql(
          mergedSchema,
          `
            query($bid: ID!) {
              node(id: $bid) {
                __typename
                id
                ...PropertyFragment
                ...BookingFragment
                ...CustomerFragment
              }
            }

            fragment PropertyFragment on Property {
              name
            }

            fragment BookingFragment on Booking {
              startTime
              endTime
            }

            fragment CustomerFragment on Customer {
              name
            }
          `,
          {},
          {},
          {
            bid: 'b1',
          },
        );

        expect(result).to.deep.equal({
          data: {
            node: {
              __typename: 'Booking',
              id: 'b1',
              startTime: '2016-05-04',
              endTime: '2016-06-03',
            },
          },
        });
      });
开发者ID:sventschui,项目名称:graphql-tools,代码行数:45,代码来源:testMergeSchemas.ts


示例8: it

  it('should match nerdy snapshot', async () => {
    const query = `
      query Q {
        jokes {
          byCategory(category: NERDY) {
            id
            text
            categories
          }
        }
      }
    `;

    const result = await graphql(schema, query, rootValue, context);
    const { data, errors } = result;

    expect({ data, errors }).toMatchSnapshot();
  });
开发者ID:Alexandr-Baluhin,项目名称:nodejs-graphql-template,代码行数:18,代码来源:joke.test.ts


示例9: exportPostGraphQLSchema

/**
 * Exports a PostGraphQL schema by looking at a Postgres client.
 */
export default async function exportPostGraphQLSchema (
  schema: GraphQLSchema,
  options: {
    exportJsonSchemaPath?: string,
    exportGqlSchemaPath?: string,
  } = {},
): Promise<void> {
  // JSON version
  if (typeof options.exportJsonSchemaPath === 'string') {
    const result = await graphql(schema, introspectionQuery)
    await writeFileAsync(options.exportJsonSchemaPath, JSON.stringify(result, null, 2))
  }

  // Schema language version
  if (typeof options.exportGqlSchemaPath === 'string') {
    await writeFileAsync(options.exportGqlSchemaPath, printSchema(schema))
  }
}
开发者ID:tim-field,项目名称:postgraphql,代码行数:21,代码来源:exportPostGraphQLSchema.ts


示例10: it

 it('Model methods are available in the schema', async () => {
     const query = `
         query {
             __schema {
                 mutationType {
                     fields {
                         name
                     }
                 }
             }
         }
     `;
     const result = await graphql(schema, query);
     expect(result.data!.__schema.mutationType.fields).to.deep.equal([
         { name: 'User_userMethod1' },
         { name: 'Post_postMethod1' },
     ]);
 });
开发者ID:RevFramework,项目名称:rev-framework,代码行数:18,代码来源:mutation_registration.tests.ts



注:本文中的graphql.graphql函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript graphql.isAbstractType函数代码示例发布时间:2022-05-25
下一篇:
TypeScript graphql.getOperationAST函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap