UNPKG

4.44 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.SCHEMA_QUERY = exports.EngineSchemaProvider = void 0;
7const graphql_tag_1 = __importDefault(require("graphql-tag"));
8const graphql_1 = require("graphql");
9const engine_1 = require("../../engine");
10const config_1 = require("../../config");
11const utilities_1 = require("../../utilities");
12class EngineSchemaProvider {
13 constructor(config, clientIdentity) {
14 this.config = config;
15 this.clientIdentity = clientIdentity;
16 }
17 async resolveSchema(override) {
18 if (this.schema && (!override || !override.force))
19 return this.schema;
20 const { engine, client } = this.config;
21 if (!this.config.graph) {
22 throw new Error(`No graph ID found for client. Please specify a graph ID via the config or the --graph flag`);
23 }
24 if (!this.client) {
25 if (!engine.apiKey) {
26 throw new Error(`No API key found. Please set ${config_1.keyEnvVar} or use --key`);
27 }
28 this.client = new engine_1.ApolloEngineClient(engine.apiKey, engine.endpoint, this.clientIdentity);
29 }
30 const { data, errors } = await this.client.execute({
31 query: exports.SCHEMA_QUERY,
32 variables: {
33 id: this.config.graph,
34 tag: override && override.tag ? override.tag : this.config.variant
35 }
36 });
37 if (errors) {
38 throw new Error(errors.map(({ message }) => message).join("\n"));
39 }
40 if (!(data && data.service && data.service.__typename === "Service")) {
41 throw new Error(`Unable to get schema from the Apollo registry for graph ${this.config.graph}`);
42 }
43 this.schema = graphql_1.buildClientSchema(data.service.schema);
44 return this.schema;
45 }
46 onSchemaChange(_handler) {
47 throw new Error("Polling of Apollo not implemented yet");
48 return () => { };
49 }
50 async resolveFederatedServiceSDL() {
51 utilities_1.Debug.error("Cannot resolve a federated service's SDL from Apollo. Use an endpoint or a file instead");
52 return;
53 }
54}
55exports.EngineSchemaProvider = EngineSchemaProvider;
56exports.SCHEMA_QUERY = graphql_tag_1.default `
57 query GetSchemaByTag($tag: String!, $id: ID!) {
58 service(id: $id) {
59 ... on Service {
60 __typename
61 schema(tag: $tag) {
62 hash
63 __schema: introspection {
64 queryType {
65 name
66 }
67 mutationType {
68 name
69 }
70 subscriptionType {
71 name
72 }
73 types(filter: { includeBuiltInTypes: true }) {
74 ...IntrospectionFullType
75 }
76 directives {
77 name
78 description
79 locations
80 args {
81 ...IntrospectionInputValue
82 }
83 }
84 }
85 }
86 }
87 }
88 }
89
90 fragment IntrospectionFullType on IntrospectionType {
91 kind
92 name
93 description
94 fields {
95 name
96 description
97 args {
98 ...IntrospectionInputValue
99 }
100 type {
101 ...IntrospectionTypeRef
102 }
103 isDeprecated
104 deprecationReason
105 }
106 inputFields {
107 ...IntrospectionInputValue
108 }
109 interfaces {
110 ...IntrospectionTypeRef
111 }
112 enumValues(includeDeprecated: true) {
113 name
114 description
115 isDeprecated
116 deprecationReason
117 }
118 possibleTypes {
119 ...IntrospectionTypeRef
120 }
121 }
122
123 fragment IntrospectionInputValue on IntrospectionInputValue {
124 name
125 description
126 type {
127 ...IntrospectionTypeRef
128 }
129 defaultValue
130 }
131
132 fragment IntrospectionTypeRef on IntrospectionType {
133 kind
134 name
135 ofType {
136 kind
137 name
138 ofType {
139 kind
140 name
141 ofType {
142 kind
143 name
144 ofType {
145 kind
146 name
147 ofType {
148 kind
149 name
150 ofType {
151 kind
152 name
153 ofType {
154 kind
155 name
156 }
157 }
158 }
159 }
160 }
161 }
162 }
163 }
164`;
165//# sourceMappingURL=engine.js.map
\No newline at end of file