Skip to content

Validating a JSON Object against GraphQL Type #2343

Closed
@rawkode

Description

@rawkode

Is it possible to validate a JSON document against a GraphQL Output Type?

I found these docs: https://graphql.org/graphql-js/utilities/

I am able to load the schema and get the types. I can't work out how to validate a JSON doc against one of those types though.

I've tried astFromValue and isValidJSValue; both without success.

Please help :)

This is where I am thus far:

jest.disableAutomock();

const fs = require("fs");
const graphql = require("graphql");
const yaml = require("js-yaml");

test("adds 1 + 2 to equal 3", () => {
  const teamMemberSchema = fs.readFileSync(
    "../../schemas/graphql/team/member.graphql",
    "utf8"
  );

  const schema = graphql.buildSchema(teamMemberSchema);

  const members = yaml.safeLoadAll(
    fs.readFileSync("../../examples/team/member.yaml", "utf8")
  );

  members.map(member => {
    const result = ???;
    console.log(result);
  });

  expect(1 + 2).toBe(3);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions