File tree Expand file tree Collapse file tree 12 files changed +848
-3
lines changed Expand file tree Collapse file tree 12 files changed +848
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { FABRuntime } from "@fab/core" ;
2
2
import { makeGraphQLHandler } from "@glenstack/cf-workers-graphql" ;
3
3
import { schema } from "./schema/index" ;
4
+ import { voyager } from "./voyager" ;
4
5
5
6
const graphQLHandler = makeGraphQLHandler ( schema ) ;
6
7
7
8
export default function graphql ( { Router } : FABRuntime ) {
8
9
Router . on ( "/graphql" , ( { request } ) => graphQLHandler ( request ) ) ;
10
+ Router . on (
11
+ "/voyager" ,
12
+ async ( ) =>
13
+ new Response ( voyager , { headers : { "Content-Type" : "text/html" } } )
14
+ ) ;
9
15
}
Original file line number Diff line number Diff line change 1
1
import { makeExecutableSchema } from "@graphql-tools/schema" ;
2
2
import gql from "graphql-tag" ;
3
+ import { typeDefs as scalarTypeDefs } from "./types/scalars" ;
4
+ import { typeDefs as relayTypeDefs } from "./types/relay" ;
5
+ import { typeDefs as documentTypeDefs } from "./types/document" ;
6
+ import { typeDefs as searchResultTypeDefs } from "./types/searchResult" ;
3
7
4
8
const typeDefs = gql `
5
9
type Query {
@@ -13,4 +17,13 @@ const resolvers = {
13
17
} ,
14
18
} ;
15
19
16
- export const schema = makeExecutableSchema ( { typeDefs, resolvers } ) ;
20
+ export const schema = makeExecutableSchema ( {
21
+ typeDefs : [
22
+ typeDefs ,
23
+ ...scalarTypeDefs ,
24
+ ...relayTypeDefs ,
25
+ documentTypeDefs ,
26
+ searchResultTypeDefs ,
27
+ ] ,
28
+ resolvers : [ resolvers ] ,
29
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { connectionDefinitions } from "graphql-relay-tools" ;
2
+ import gql from "graphql-tag" ;
3
+
4
+ const { connectionType : DocumentConnection } = connectionDefinitions ( {
5
+ name : "Document" ,
6
+ } ) ;
7
+
8
+ export const typeDefs = gql `
9
+ type Document implements Node {
10
+ id: ID!
11
+ url: URL!
12
+ }
13
+
14
+ ${ DocumentConnection }
15
+ ` ;
Original file line number Diff line number Diff line change
1
+ import { typeDefs as nodeTypeDefs } from "./node" ;
2
+ import { typeDefs as pageInfoTypeDefs } from "./pageInfo" ;
3
+
4
+ export const typeDefs = [ nodeTypeDefs , pageInfoTypeDefs ] ;
Original file line number Diff line number Diff line change
1
+ import gql from "graphql-tag" ;
2
+ import { nodeInterface , nodeField } from "graphql-relay-tools" ;
3
+
4
+ export const typeDefs = gql `
5
+ ${ nodeInterface }
6
+
7
+ extend type Query {
8
+ ${ nodeField }
9
+ }
10
+ ` ;
Original file line number Diff line number Diff line change
1
+ import gql from "graphql-tag" ;
2
+ import { pageInfoType } from "graphql-relay-tools" ;
3
+
4
+ export const typeDefs = gql `
5
+ ${ pageInfoType }
6
+ ` ;
Original file line number Diff line number Diff line change
1
+ import { typeDefs as urlTypeDefs } from "./url" ;
2
+
3
+ export const typeDefs = [ urlTypeDefs ] ;
Original file line number Diff line number Diff line change
1
+ import gql from "graphql-tag" ;
2
+
3
+ export const typeDefs = gql `
4
+ scalar URL
5
+ ` ;
Original file line number Diff line number Diff line change
1
+ import { connectionArgs } from "graphql-relay-tools" ;
2
+ import gql from "graphql-tag" ;
3
+
4
+ export const typeDefs = gql `
5
+ type SearchResult {
6
+ documents${ connectionArgs ( ) } : DocumentConnection!
7
+ }
8
+
9
+ extend type Query {
10
+ search(query: String!): SearchResult!
11
+ }
12
+ ` ;
Original file line number Diff line number Diff line change
1
+ export const voyager = `<!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script src="https://cdn.jsdelivr.net/npm/react@16/umd/react.production.min.js"></script>
5
+ <script src="https://cdn.jsdelivr.net/npm/react-dom@16/umd/react-dom.production.min.js"></script>
6
+
7
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/graphql-voyager/dist/voyager.css" />
8
+ <script src="https://cdn.jsdelivr.net/npm/graphql-voyager/dist/voyager.min.js"></script>
9
+ </head>
10
+ <body>
11
+ <div id="voyager">Loading...</div>
12
+ <script>
13
+ function introspectionProvider(introspectionQuery) {
14
+ return fetch('/graphql', {
15
+ method: 'POST',
16
+ headers: { 'Content-Type': 'application/json' },
17
+ body: JSON.stringify({ query: introspectionQuery }),
18
+ credentials: 'include'
19
+ }).then(function (response) {
20
+ return response.json()
21
+ })
22
+ }
23
+
24
+ GraphQLVoyager.init(document.getElementById('voyager'), {
25
+ introspection: introspectionProvider
26
+ })
27
+ </script>
28
+ </body>
29
+ </html>` ;
You can’t perform that action at this time.
0 commit comments