Skip to content

Commit

Permalink
more flexible getSchema function
Browse files Browse the repository at this point in the history
  • Loading branch information
singingwolfboy committed Oct 13, 2019
1 parent e1aff3d commit 66700c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 5 additions & 6 deletions packages/jest-serializer-graphql-schema/README.md
Expand Up @@ -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() }),
Expand All @@ -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:
Expand Down Expand Up @@ -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();
});
});;
```
Expand Up @@ -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() }),
Expand All @@ -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();
});

0 comments on commit 66700c6

Please sign in to comment.