"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupSimpleCase = setupSimpleCase;
exports.setupVariablesCase = setupVariablesCase;
exports.setupMaskedVariablesCase = setupMaskedVariablesCase;
exports.addDelayToMocks = addDelayToMocks;
exports.setupPaginatedCase = setupPaginatedCase;
const rxjs_1 = require("rxjs");
const client_1 = require("@apollo/client");
function setupSimpleCase() {
    const query = (0, client_1.gql) `
    query GreetingQuery {
      greeting
    }
  `;
    const mocks = [
        {
            request: { query },
            result: { data: { greeting: "Hello" } },
            delay: 20,
        },
    ];
    return { query, mocks };
}
function setupVariablesCase() {
    const query = (0, client_1.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 };
}
function setupMaskedVariablesCase() {
    const document = (0, client_1.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 };
}
function addDelayToMocks(mocks, delay = 150, override = false) {
    return mocks.map((mock) => override ? { ...mock, delay } : { delay, ...mock });
}
function setupPaginatedCase() {
    const query = (0, client_1.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 client_1.ApolloLink((operation) => {
        const { offset = 0, limit = 2 } = operation.variables;
        const letters = data.slice(offset, offset + limit);
        return new rxjs_1.Observable((observer) => {
            setTimeout(() => {
                observer.next({ data: { letters } });
                observer.complete();
            }, 10);
        });
    });
    return { query, link, data };
}
//# sourceMappingURL=index.cjs.map
