Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using GraphQL Voyager without the endpoint #238

Open
isha-talegaonkar opened this issue Jul 13, 2022 · 5 comments
Open

Using GraphQL Voyager without the endpoint #238

isha-talegaonkar opened this issue Jul 13, 2022 · 5 comments

Comments

@isha-talegaonkar
Copy link

My project does not have a graphql endpoint as such, but a bunch of input graphql schema files that I am getting using an API. I need to visualize the file that I am getting as input. Is there any way to do so?

@LunaticMuch
Copy link
Collaborator

@isha-talegaonkar you can build an introspection from file and use it. If you check the demo, you can get some clues on how to make it.

@isha-talegaonkar
Copy link
Author

isha-talegaonkar commented Jul 14, 2022 via email

@jobaeurle
Copy link

Is this possible with the standalone version? It's probably easiest to use sdlToIntrospection and then give the result as introspection object to the init function....
But I guess sdlToIntrospection isn't exposed?!

@LunaticMuch
Copy link
Collaborator

@isha-talegaonkar you might need to provide more info regarding your project.

You can always build and dump a complete SDL or get an introspection.
Almost any library can do it.

@nicolas-despres
Copy link

Here is an example on how you can do this without an endpoint:

import {
    Source,
    parse,
    execute,
    buildSchema,
} from 'graphql'
import type {
    DocumentNode,
} from 'graphql'
import { Voyager, voyagerIntrospectionQuery } from 'graphql-voyager';


var schema = buildSchema(`
  type Account {
    Id: String
    Name: String
  }

  type Objects {
    Account: Account
  }

  type UIAPI {
    query: Objects
  }

  type Query {
    Account(Id: String): Account
    uiapi: UIAPI
  }
`)

async function retrieveDemoIntrospection(introspectionQuery){
    let documentAST: DocumentNode | undefined;
    try {
        //const params = await getGraphQLParams(request)
        documentAST = parse(new Source(introspectionQuery, 'GraphQL request'));
    } catch (syntaxError: unknown) {
        // Return 400: Bad Request if any syntax errors exist.
        //documentAST = new DocumentNode()
        throw new Error("failed")
    }

    return execute({
        schema,
        document: documentAST,
        rootValue: {},
        contextValue: {},
        variableValues: {},
        operationName: "IntrospectionQuery",
        fieldResolver: undefined,
        typeResolver: undefined,
    });
}

You can extend field and type resolver which can be very helpful when you schema is dynamic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants