Open isha-talegaonkar opened 2 years ago
@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.
Hi, I am still unsure on how I can go about this. Can you please point me towards some files I can look at to understand better?
Thanks, Isha
On Wed, Jul 13, 2022 at 1:08 PM Stefano @.***> wrote:
@isha-talegaonkar https://github.com/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.
— Reply to this email directly, view it on GitHub https://github.com/IvanGoncharov/graphql-voyager/issues/238#issuecomment-1183629654, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH3FGXFODVXGXTGM4DESOETVT4O4NANCNFSM53PQNQ5A . You are receiving this because you were mentioned.Message ID: @.***>
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?!
@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.
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.
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?