From 66700c69671bacb15404cfc360421f5762dfcff9 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Sun, 13 Oct 2019 13:45:06 +0200 Subject: [PATCH] more flexible getSchema function --- packages/jest-serializer-graphql-schema/README.md | 11 +++++------ .../__tests__/schema.test.ts | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/jest-serializer-graphql-schema/README.md b/packages/jest-serializer-graphql-schema/README.md index 4f9f027ea..ac2ccac90 100644 --- a/packages/jest-serializer-graphql-schema/README.md +++ b/packages/jest-serializer-graphql-schema/README.md @@ -43,8 +43,7 @@ import { buildClientSchema, } from "graphql"; -const getPokemonSchema = async () => { - const url = "https://graphql-pokemon.now.sh"; +const getSchema = async (url: string) => { const response = await fetch(url, { method: "POST", body: JSON.stringify({ query: getIntrospectionQuery() }), @@ -57,9 +56,9 @@ const getPokemonSchema = async () => { }; test("Pokemon GraphQL API has a consistent schema", async () => { - const schema = await getPokemonSchema(); + const schema = await getSchema("https://graphql-pokemon.now.sh"); expect(schema).toMatchSnapshot(); -}); +});; ``` This test will produce the following snapshot: @@ -176,7 +175,7 @@ content of your schema, sort your schema before calling import { lexicographicSortSchema } from "graphql"; test("Pokemon GraphQL API has a consistent schema", async () => { - const schema = await getPokemonSchema(); + const schema = await getSchema("https://graphql-pokemon.now.sh"); expect(lexicographicSortSchema(schema)).toMatchSnapshot(); -}); +});; ``` \ No newline at end of file diff --git a/packages/jest-serializer-graphql-schema/__tests__/schema.test.ts b/packages/jest-serializer-graphql-schema/__tests__/schema.test.ts index 1b0e35199..ff093a69c 100644 --- a/packages/jest-serializer-graphql-schema/__tests__/schema.test.ts +++ b/packages/jest-serializer-graphql-schema/__tests__/schema.test.ts @@ -8,8 +8,7 @@ import { const GraphQLSchemaSnapshotSerializer = require("../src"); expect.addSnapshotSerializer(GraphQLSchemaSnapshotSerializer); -const getPokemonSchema = async () => { - const url = "https://graphql-pokemon.now.sh"; +const getSchema = async (url: string) => { const response = await fetch(url, { method: "POST", body: JSON.stringify({ query: getIntrospectionQuery() }), @@ -22,6 +21,6 @@ const getPokemonSchema = async () => { }; test("Pokemon GraphQL API has a consistent schema", async () => { - const schema = await getPokemonSchema(); + const schema = await getSchema("https://graphql-pokemon.now.sh"); expect(schema).toMatchSnapshot(); });