How to use the apollo-codegen-core/lib/loading.loadSchema function in apollo-codegen-core

To help you get started, we’ve selected a few apollo-codegen-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / __tests__ / types.ts View on Github external
import {
  GraphQLString,
  GraphQLInt,
  GraphQLFloat,
  GraphQLBoolean,
  GraphQLID,
  GraphQLList,
  GraphQLNonNull,
  GraphQLScalarType
} from "graphql";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const schema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);

import { typeNameFromGraphQLType } from "../types";

describe("Scala code generation: Types", function() {
  describe("#typeNameFromGraphQLType()", function() {
    test("should return OptionalResult[String] for GraphQLString", function() {
      expect(typeNameFromGraphQLType({ options: {} }, GraphQLString)).toBe(
        "com.apollographql.scalajs.OptionalValue[String]"
      );
    });

    test("should return String for GraphQLNonNull(GraphQLString)", function() {
      expect(
        typeNameFromGraphQLType(
github apollographql / apollo-tooling / packages / apollo / src / __tests__ / validation.ts View on Github external
import * as path from "path";

import {
  loadSchema,
  loadAndMergeQueryDocuments
} from "apollo-codegen-core/lib/loading";

import { validateQueryDocument } from "../validation";

const schema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);

describe("Validation", () => {
  function loadQueryDocument(filename: string) {
    return loadAndMergeQueryDocuments([
      path.join(__dirname, "../../../../__fixtures__/starwars", filename)
    ]);
  }

  test(`should throw an error for AnonymousQuery.graphql`, () => {
    const document = loadQueryDocument("AnonymousQuery.graphql");

    expect(() => validateQueryDocument(schema, document)).toThrow(
      "Validation of GraphQL query document failed"
    );
github apollographql / apollo-tooling / packages / apollo-codegen-flow / src / __tests__ / codeGeneration.ts View on Github external
test("handles multiline graphql comments", () => {
    const miscSchema = loadSchema(
      require.resolve("../../../../__fixtures__/misc/schema.json")
    );

    const document = parse(`
      query CustomScalar {
        commentTest {
          multiLine
        }
      }
    `);

    const output = generateSource(
      compileToIR(miscSchema, document, {
        mergeInFieldsFromFragmentSpreads: true,
        addTypename: true
      })
github apollographql / apollo-tooling / packages / apollo-codegen-typescript-legacy / src / __tests__ / codeGeneration.js View on Github external
import { parse } from "graphql";

import { generateSource } from "../codeGeneration";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const starWarsSchema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);
const miscSchema = loadSchema(
  require.resolve("../../../../__fixtures__/misc/schema.json")
);

import CodeGenerator from "apollo-codegen-core/lib/utilities/CodeGenerator";

import { compileToLegacyIR } from "apollo-codegen-core/lib/compiler/legacyIR";

describe("TypeScript code generation", function() {
  let generator;
  let compileFromSource;
  let addFragment;

  function setup(schema) {
    const context = {
      schema: schema,
      operations: {},
github apollographql / apollo-tooling / packages / apollo-codegen-typescript-legacy / src / __tests__ / codeGeneration.js View on Github external
import { parse } from "graphql";

import { generateSource } from "../codeGeneration";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const starWarsSchema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);
const miscSchema = loadSchema(
  require.resolve("../../../../__fixtures__/misc/schema.json")
);

import CodeGenerator from "apollo-codegen-core/lib/utilities/CodeGenerator";

import { compileToLegacyIR } from "apollo-codegen-core/lib/compiler/legacyIR";

describe("TypeScript code generation", function() {
  let generator;
  let compileFromSource;
  let addFragment;

  function setup(schema) {
github apollographql / apollo-tooling / packages / apollo-codegen-flow-legacy / src / __tests__ / codeGeneration.js View on Github external
import { parse } from "graphql";

import { generateSource } from "../codeGeneration";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const starWarsSchema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);
const miscSchema = loadSchema(
  require.resolve("../../../../__fixtures__/misc/schema.json")
);

import CodeGenerator from "apollo-codegen-core/lib/utilities/CodeGenerator";

import { compileToLegacyIR } from "apollo-codegen-core/lib/compiler/legacyIR";

function setup(schema) {
  const context = {
    schema: schema,
    operations: {},
    fragments: {},
    typesUsed: {}
github apollographql / apollo-tooling / packages / apollo-codegen-typescript / src / __tests__ / codeGeneration.ts View on Github external
import { parse } from "graphql";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const schema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);
const miscSchema = loadSchema(
  require.resolve("../../../../__fixtures__/misc/schema.json")
);

import {
  compileToIR,
  CompilerOptions,
  CompilerContext
} from "apollo-codegen-core/lib/compiler";

import {
  generateSource,
  generateLocalSource,
  generateGlobalSource
github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / __tests__ / codeGeneration.ts View on Github external
import {
  parse,
  GraphQLNonNull,
  GraphQLString,
  GraphQLEnumType,
  GraphQLList
} from "graphql";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const schema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);

import {
  compileToIR,
  CompilerOptions,
  CompilerContext,
  SelectionSet,
  Field,
  Argument
} from "apollo-codegen-core/lib/compiler";

import { SwiftAPIGenerator } from "../codeGeneration";

describe("Swift code generation", () => {
  let generator: SwiftAPIGenerator;
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / __tests__ / codeGeneration.ts View on Github external
GraphQLNonNull,
  GraphQLEnumType,
  GraphQLCompositeType,
  GraphQLObjectType
} from "graphql";

import {
  generateSource,
  classDeclarationForOperation,
  traitDeclarationForFragment,
  traitDeclarationForSelectionSet,
  typeDeclarationForGraphQLType
} from "../codeGeneration";

import { loadSchema } from "apollo-codegen-core/lib/loading";
const schema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);

import CodeGenerator from "apollo-codegen-core/lib/utilities/CodeGenerator";

import {
  compileToLegacyIR,
  LegacyCompilerContext
} from "apollo-codegen-core/lib/compiler/legacyIR";

describe("Scala code generation", function() {
  let generator;
  let resetGenerator;
  let compileFromSource;
  let addFragment;
github apollographql / apollo-tooling / packages / apollo-language-server / src / __tests__ / diagnostics.ts View on Github external
import { Source } from "graphql";
import { loadSchema } from "apollo-codegen-core/lib/loading";
import { GraphQLDocument } from "../document";
import { collectExecutableDefinitionDiagnositics } from "../diagnostics";
const schema = loadSchema(
  require.resolve("../../../../__fixtures__/starwars/schema.json")
);
const validDocument = new GraphQLDocument(
  new Source(`
    query HeroAndFriendsNames {
      hero {
        name
        friends {
          name
        }
      }
    }`)
);
const invalidDocument = new GraphQLDocument(
  new Source(`
    query HeroAndFriendsNames {