import assert from "assert";
import { introspectStarwars } from './introspectStarwars';
import { initTemplateStringTransformer } from '../src/index';
import fs from 'fs';
import path from 'path';

// Uncomment the below to generate a new schema JSON
// describe("graphql", () => {
//   it("can introspect star wars", async () => {
//     const result = await introspectStarwars();
//
//     fs.writeFileSync(path.join(__dirname, "starwars.json"),
//       JSON.stringify(result, null, 2));
//
//     assert.ok(result.data);
//     assert.ok(result.data.__schema);
//   });
// });

describe("runtime query transformer", () => {
  it("can be initialized with an introspected query", async () => {
    const result = await introspectStarwars();
    const transformer = initTemplateStringTransformer(result.data);
  });

  it("can compile a Relay.QL query", () => {
    Relay.QL`
      query HeroNameQuery {
        hero {
          name
        }
      }
    `;
  });

  it("can transform a simple query", async () => {
    const result = await introspectStarwars();
    const transformer = initTemplateStringTransformer(result.data);
    const transformed = transformer(`
      query HeroNameAndFriendsQuery {
        hero {
          id
          name
          friends {
            name
          }
        }
      }
    `);

    const expected = Relay.QL`
      query HeroNameAndFriendsQuery {
        hero {
          id
          name
          friends {
            name
          }
        }
      }
    `;

    assert.deepEqual(transformed, expected);
  });
});

@@ -1557,13 +1557,504 @@
 );%0A  %7D);
+%0A%0A  it(%22can transform a query with arguments%22, async () =%3E %7B%0A    const result = await introspectStarwars();%0A    const transformer = initTemplateStringTransformer(result.data);%0A    const transformed = transformer(%60%0A      query FetchLukeQuery %7B%0A        human(id: %221000%22) %7B%0A          name%0A        %7D%0A      %7D%0A    %60);%0A%0A    const expected = Relay.QL%60%0A      query FetchLukeQuery %7B%0A        human(id: %221000%22) %7B%0A          name%0A        %7D%0A      %7D%0A    %60;%0A%0A    assert.deepEqual(transformed, expected);%0A  %7D)
 %0A%7D);%0A

Add another test