"use strict";

var _graphql = require("graphql");

var _getQueryFacts = require("../getQueryFacts");

/**
 *  Copyright (c) 2019 GraphQL Contributors.
 *
 *  This source code is licensed under the MIT license found in the
 *  LICENSE file in the root directory of this source tree.
 */
describe('collectVariables', () => {
  const TestType = new _graphql.GraphQLObjectType({
    name: 'Test',
    fields: {
      id: {
        type: _graphql.GraphQLID
      },
      string: {
        type: _graphql.GraphQLString
      },
      int: {
        type: _graphql.GraphQLInt
      },
      float: {
        type: _graphql.GraphQLFloat
      },
      boolean: {
        type: _graphql.GraphQLBoolean
      }
    }
  });
  const TestSchema = new _graphql.GraphQLSchema({
    query: TestType
  });
  it('returns an empty object if no variables exist', () => {
    const variableToType = (0, _getQueryFacts.collectVariables)(TestSchema, (0, _graphql.parse)('{ id }'));
    expect(variableToType).toEqual({});
  });
  it('collects variable types from a schema and query', () => {
    const variableToType = (0, _getQueryFacts.collectVariables)(TestSchema, (0, _graphql.parse)(`
      query ($foo: Int, $bar: String) { id }
    `));
    expect(Object.keys(variableToType)).toEqual(['foo', 'bar']);
    expect(variableToType.foo).toEqual(_graphql.GraphQLInt);
    expect(variableToType.bar).toEqual(_graphql.GraphQLString);
  });
  it('collects variable types from multiple queries', () => {
    const variableToType = (0, _getQueryFacts.collectVariables)(TestSchema, (0, _graphql.parse)(`
      query A($foo: Int, $bar: String) { id }
      query B($foo: Int, $baz: Float) { id }
    `));
    expect(Object.keys(variableToType)).toEqual(['foo', 'bar', 'baz']);
    expect(variableToType.foo).toEqual(_graphql.GraphQLInt);
    expect(variableToType.bar).toEqual(_graphql.GraphQLString);
    expect(variableToType.baz).toEqual(_graphql.GraphQLFloat);
  });
});