All Downloads are FREE. Search and download functionalities are using the official Maven repository.

node_modules.graphql-import.dist.index.test.js Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ava_1 = require("ava");
var _1 = require(".");
ava_1.default('parseImportLine: parse single import', function (t) {
    t.deepEqual(_1.parseImportLine("import A from \"schema.graphql\""), {
        imports: ['A'],
        from: 'schema.graphql',
    });
});
ava_1.default('parseImportLine: invalid', function (t) {
    t.throws(function () { return _1.parseImportLine("import from \"schema.graphql\""); }, Error);
});
ava_1.default('parseImportLine: invalid 2', function (t) {
    t.throws(function () { return _1.parseImportLine("import A from \"\""); }, Error);
});
ava_1.default('parseImportLine: parse multi import', function (t) {
    t.deepEqual(_1.parseImportLine("import A, B from \"schema.graphql\""), {
        imports: ['A', 'B'],
        from: 'schema.graphql',
    });
});
ava_1.default('parseImportLine: parse multi import (weird spacing)', function (t) {
    t.deepEqual(_1.parseImportLine("import  A  ,B   from \"schema.graphql\""), {
        imports: ['A', 'B'],
        from: 'schema.graphql',
    });
});
ava_1.default('parseImportLine: different path', function (t) {
    t.deepEqual(_1.parseImportLine("import A from \"../new/schema.graphql\""), {
        imports: ['A'],
        from: '../new/schema.graphql',
    });
});
ava_1.default('parseSDL: non-import comment', function (t) {
    t.deepEqual(_1.parseSDL("#importent: comment"), []);
});
ava_1.default('parse: multi line import', function (t) {
    var sdl = "# import A from \"a.graphql\"\n# import * from \"b.graphql\"\n  ";
    t.deepEqual(_1.parseSDL(sdl), [
        {
            imports: ['A'],
            from: 'a.graphql',
        },
        {
            imports: ['*'],
            from: 'b.graphql',
        },
    ]);
});
ava_1.default('importSchema: imports only', function (t) {
    var expectedSDL = "type Query {\n  first: String\n  second: Float\n  third: String\n}\n";
    t.is(_1.importSchema('fixtures/imports-only/all.graphql'), expectedSDL);
});
ava_1.default('importSchema: field types', function (t) {
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  c: C\n  hello: String!\n}\n\ntype C {\n  id: ID!\n}\n";
    t.is(_1.importSchema('fixtures/field-types/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: enums', function (t) {
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\nenum B {\n  B1\n  B2\n  B3\n}\n";
    t.is(_1.importSchema('fixtures/enums/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: import all', function (t) {
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  hello: String!\n  c1: C1\n  c2: C2\n}\n\ntype C1 {\n  id: ID!\n}\n\ntype C2 {\n  id: ID!\n}\n";
    t.is(_1.importSchema('fixtures/import-all/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: import all from objects', function (t) {
    var schemaC = "\n    type C1 {\n      id: ID!\n    }\n\n    type C2 {\n      id: ID!\n    }\n\n    type C3 {\n      id: ID!\n    }";
    var schemaB = "\n    # import * from 'schemaC'\n\n    type B {\n      hello: String!\n      c1: C1\n      c2: C2\n    }";
    var schemaA = "\n    # import B from 'schemaB'\n\n    type A {\n      # test 1\n      first: String\n      second: Float\n      b: B\n    }";
    var schemas = {
        schemaA: schemaA, schemaB: schemaB, schemaC: schemaC
    };
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  hello: String!\n  c1: C1\n  c2: C2\n}\n\ntype C1 {\n  id: ID!\n}\n\ntype C2 {\n  id: ID!\n}\n";
    t.is(_1.importSchema(schemaA, schemas), expectedSDL);
});
ava_1.default("importSchema: single object schema", function (t) {
    var schemaA = "\n    type A {\n      field: String\n    }";
    var expectedSDL = "type A {\n  field: String\n}\n";
    t.is(_1.importSchema(schemaA), expectedSDL);
});
ava_1.default("importSchema: import all mix 'n match", function (t) {
    var schemaB = "\n    # import C1, C2 from 'fixtures/import-all/c.graphql'\n\n    type B {\n      hello: String!\n      c1: C1\n      c2: C2\n    }";
    var schemaA = "\n    # import * from \"schemaB\"\n\n    type A {\n      # test 1\n      first: String\n      second: Float\n      b: B\n    }";
    var schemas = {
        schemaB: schemaB
    };
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  hello: String!\n  c1: C1\n  c2: C2\n}\n\ntype C1 {\n  id: ID!\n}\n\ntype C2 {\n  id: ID!\n}\n";
    t.is(_1.importSchema(schemaA, schemas), expectedSDL);
});
ava_1.default("importSchema: import all mix 'n match 2", function (t) {
    var schemaA = "\n    # import * from \"fixtures/import-all/b.graphql\"\n\n    type A {\n      # test 1\n      first: String\n      second: Float\n      b: B\n    }";
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  hello: String!\n  c1: C1\n  c2: C2\n}\n\ntype C1 {\n  id: ID!\n}\n\ntype C2 {\n  id: ID!\n}\n";
    t.is(_1.importSchema(schemaA), expectedSDL);
});
ava_1.default('importSchema: unions', function (t) {
    var expectedSDL = "type A {\n  b: B\n}\n\nunion B = C1 | C2\n\ntype C1 {\n  c1: ID\n}\n\ntype C2 {\n  c2: ID\n}\n";
    t.is(_1.importSchema('fixtures/unions/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: scalar', function (t) {
    var expectedSDL = "type A {\n  b: B\n}\n\nscalar B\n";
    t.is(_1.importSchema('fixtures/scalar/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: directive', function (t) {
    var expectedSDL = "type A {\n  first: String @upper\n  second: String @withB @deprecated\n}\n\ndirective @upper on FIELD_DEFINITION\n\nscalar B\n\ndirective @withB(argB: B) on FIELD_DEFINITION\n";
    t.is(_1.importSchema('fixtures/directive/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: interfaces', function (t) {
    var expectedSDL = "type A implements B {\n  first: String\n  second: Float\n}\n\ninterface B {\n  second: Float\n  c: [C!]!\n}\n\ntype C {\n  c: ID!\n}\n";
    t.is(_1.importSchema('fixtures/interfaces/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: interfaces-implements', function (t) {
    var expectedSDL = "type A implements B {\n  id: ID!\n}\n\ninterface B {\n  id: ID!\n}\n\ntype B1 implements B {\n  id: ID!\n}\n";
    t.is(_1.importSchema('fixtures/interfaces-implements/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: input types', function (t) {
    var expectedSDL = "type A {\n  first(b: B): String\n  second: Float\n}\n\ninput B {\n  hello: [C!]!\n}\n\ninput C {\n  id: ID!\n}\n";
    t.is(_1.importSchema('fixtures/input-types/a.graphql'), expectedSDL);
});
ava_1.default('importSchema: complex test', function (t) {
    t.notThrows(function () {
        _1.importSchema('fixtures/complex/a.graphql');
    });
});
ava_1.default('circular imports', function (t) {
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  hello: String!\n  c1: C1\n  c2: C2\n  a: A\n}\n\ntype C1 {\n  id: ID!\n}\n\ntype C2 {\n  id: ID!\n}\n";
    var actualSDL = _1.importSchema('fixtures/circular/a.graphql');
    t.is(actualSDL, expectedSDL);
});
ava_1.default('related types', function (t) {
    var expectedSDL = "type A {\n  first: String\n  second: Float\n  b: B\n}\n\ntype B {\n  hello: String!\n  c1: C\n}\n\ntype C {\n  field: String\n}\n";
    var actualSDL = _1.importSchema('fixtures/related-types/a.graphql');
    t.is(actualSDL, expectedSDL);
});
ava_1.default('relative paths', function (t) {
    var expectedSDL = "type Query {\n  feed: [Post!]!\n}\n\ntype Mutation {\n  createDraft(title: String!, text: String): Post\n  publish(id: ID!): Post\n}\n\ntype Post implements Node {\n  id: ID!\n  isPublished: Boolean!\n  title: String!\n  text: String!\n}\n\ninterface Node {\n  id: ID!\n}\n";
    var actualSDL = _1.importSchema('fixtures/relative-paths/src/schema.graphql');
    t.is(actualSDL, expectedSDL);
});
ava_1.default('root field imports', function (t) {
    var expectedSDL = "type Dummy {\n  field: String\n}\n\ntype Query {\n  posts(filter: PostFilter): [Post]\n}\n\ntype Post {\n  field1: String\n}\n\ninput PostFilter {\n  field3: Int\n}\n";
    var actualSDL = _1.importSchema('fixtures/root-fields/a.graphql');
    t.is(actualSDL, expectedSDL);
});
ava_1.default('merged root field imports', function (t) {
    var expectedSDL = "type Dummy {\n  field: String\n}\n\ntype Query {\n  helloA: String\n  posts(filter: PostFilter): [Post]\n  hello: String\n}\n\ntype Post {\n  field1: String\n}\n\ninput PostFilter {\n  field3: Int\n}\n";
    var actualSDL = _1.importSchema('fixtures/merged-root-fields/a.graphql');
    t.is(actualSDL, expectedSDL);
});
ava_1.default('missing type on type', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/a.graphql'); }, Error);
    t.is(err.message, "Field test: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing type on interface', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/b.graphql'); }, Error);
    t.is(err.message, "Field test: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing type on input type', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/c.graphql'); }, Error);
    t.is(err.message, "Field post: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing interface type', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/d.graphql'); }, Error);
    t.is(err.message, "Couldn't find interface MyInterface in any of the schemas.");
});
ava_1.default('missing union type', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/e.graphql'); }, Error);
    t.is(err.message, "Couldn't find type C in any of the schemas.");
});
ava_1.default('missing type on input type', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/f.graphql'); }, Error);
    t.is(err.message, "Field myfield: Couldn't find type Post in any of the schemas.");
});
ava_1.default('missing type on directive', function (t) {
    var err = t.throws(function () { return _1.importSchema('fixtures/type-not-found/g.graphql'); }, Error);
    t.is(err.message, "Directive first: Couldn't find type first in any of the schemas.");
});
//# sourceMappingURL=index.test.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy