import { Observable } from "rxjs";
import { ApolloLink, gql } from "@apollo/client";
export function setupSimpleCase() {
    const query = gql `
    query GreetingQuery {
      greeting
    }
  `;
    const mocks = [
        {
            request: { query },
            result: { data: { greeting: "Hello" } },
            delay: 20,
        },
    ];
    return { query, mocks };
}
export function setupVariablesCase() {
    const query = gql `
      query CharacterQuery($id: ID!) {
        character(id: $id) {
          id
          name
        }
      }
    `;
    const CHARACTERS = ["Spider-Man", "Black Widow", "Iron Man", "Hulk"];
    const mocks = [
        ...CHARACTERS,
    ].map((name, index) => ({
        request: { query, variables: { id: String(index + 1) } },
        result: {
            data: {
                character: { __typename: "Character", id: String(index + 1), name },
            },
        },
        delay: 20,
    }));
    return { mocks, query };
}
export function setupMaskedVariablesCase() {
    const document = gql `
    query CharacterQuery($id: ID!) {
      character(id: $id) {
        id
        ...CharacterFragment
      }
    }

    fragment CharacterFragment on Character {
      name
    }
  `;
    const query = document;
    const unmaskedQuery = document;
    const CHARACTERS = ["Spider-Man", "Black Widow", "Iron Man", "Hulk"];
    const mocks = [...CHARACTERS].map((name, index) => ({
        request: { query, variables: { id: String(index + 1) } },
        result: {
            data: {
                character: { __typename: "Character", id: String(index + 1), name },
            },
        },
        delay: 20,
    }));
    return { mocks, query, unmaskedQuery };
}
export function addDelayToMocks(mocks, delay = 150, override = false) {
    return mocks.map((mock) => override ? { ...mock, delay } : { delay, ...mock });
}
export function setupPaginatedCase() {
    const query = gql `
      query LettersQuery($limit: Int, $offset: Int) {
        letters(limit: $limit, offset: $offset) {
          letter
          position
        }
      }
    `;
    const data = "ABCDEFGHIJKLMNOPQRSTUV".split("").map((letter, index) => ({
        __typename: "Letter",
        letter,
        position: index + 1,
    }));
    const link = new ApolloLink((operation) => {
        const { offset = 0, limit = 2 } = operation.variables;
        const letters = data.slice(offset, offset + limit);
        return new Observable((observer) => {
            setTimeout(() => {
                observer.next({ data: { letters } });
                observer.complete();
            }, 10);
        });
    });
    return { query, link, data };
}
//# sourceMappingURL=index.js.map
