Example #1
0
 return __generator(this, function (_a) {
     switch (_a.label) {
         case 0: return [4 /*yield*/, this.resolveIntrospection()];
         case 1:
             introspection = _a.sent();
             return [2 /*return*/, graphql_1.buildClientSchema(introspection.data)];
     }
 });
Example #2
0
 return this.getIntrospection().then(introspection => {
   const schema = buildClientSchema(introspection);
   proxyRemoteFields.call(this, schema._queryType);
   proxyRemoteFields.call(this, schema._mutationType);
   proxyRemoteFields.call(this, schema._subscriptionType);
   this.schema = schema;
   return schema;
 });
function getSchema(
  schemaProvider: GraphQLSchemaProvider,
  fileOptions: BabelFileOpts,
): GraphQLSchema {
  const schemaReference =
    typeof schemaProvider === 'function' ? schemaProvider() : schemaProvider;
  const introspection =
    typeof schemaReference === 'string'
      ? getSchemaIntrospection(schemaReference, fileOptions.sourceRoot)
      : schemaReference;
  if (introspection.__schema) {
    return buildClientSchema((introspection: any));
  } else if (introspection.data && introspection.data.__schema) {
    return buildClientSchema((introspection.data: any));
  } else if (introspection.kind && introspection.kind === 'Document') {
    return buildASTSchema(introspection);
  }

  throw new Error(
    'Invalid introspection data supplied to the Babel Relay plugin. The ' +
      'resulting schema is not an object with a `__schema` property or ' +
      'a schema IDL language.',
  );
}
Example #4
0
const downloadMetaphysicsSchema = async endpoint => {
  const postBody = {
    query: introspectionQuery,
    operationName: "IntrospectionQuery",
  }

  const response = await fetch(endpoint, {
    method: "POST",
    body: JSON.stringify(postBody),
    headers: {
      "Content-Type": "application/json",
    },
  })
  const { data } = await response.json()
  // commentDescriptions is hidden
  // @ts-ignore
  return printSchema(buildClientSchema(data), { commentDescriptions: true })
}
Example #5
0
    }).then(result => {
      // If a schema was provided while this fetch was underway, then
      // satisfy the race condition by respecting the already
      // provided schema.
      if (this.state.schema !== undefined) {
        return;
      }

      if (result && result.data) {
        const schema = buildClientSchema(result.data);
        const queryFacts = getQueryFacts(schema, this.state.query);
        this.setState({ schema, ...queryFacts });
      } else {
        const responseString = typeof result === 'string' ?
          result :
          JSON.stringify(result, null, 2);
        this.setState({ response: responseString });
      }
    }).catch(error => {
Example #6
0
 return __generator(this, function (_a) {
     switch (_a.label) {
         case 0: return [4 /*yield*/, client.introspect(serviceName, stageName, token)];
         case 1:
             introspection = _a.sent();
             schema = graphql_1.buildClientSchema(introspection);
             sdl = graphql_1.printSchema(schema);
             document = graphql_1.parse(sdl);
             groupedDefinitions = lodash_1.groupBy(document.definitions, classifyDefinition);
             sortedDefinitions = [];
             typesOrder.map(function (type) {
                 var definitions = groupedDefinitions[type];
                 sortedDefinitions = sortedDefinitions.concat(definitions);
             });
             newSdl = graphql_1.print({
                 kind: graphql_1.Kind.DOCUMENT,
                 definitions: sortedDefinitions,
             });
             newDocument = graphql_1.parse(newSdl);
             countOffset = 0;
             charOffset = 0;
             typesOrder.forEach(function (type, index) {
                 if (!groupedDefinitions[type]) {
                     return;
                 }
                 var definitionCount = groupedDefinitions[type].length;
                 var definitions = newDocument.definitions.slice(countOffset, definitionCount);
                 var start = definitions[0].loc.start;
                 var comment = (index > 0 ? '\n' : '') + "#\n# " + descriptions[type] + "\n#\n\n";
                 newSdl =
                     newSdl.slice(0, start + charOffset) +
                         comment +
                         newSdl.slice(start + charOffset);
                 charOffset += comment.length;
                 countOffset += definitionCount;
             });
             header = "# THIS FILE HAS BEEN AUTO-GENERATED BY \"PRISMA DEPLOY\"\n# DO NOT EDIT THIS FILE DIRECTLY\n\n";
             return [2 /*return*/, header + newSdl];
     }
 });
Example #7
0
  async getSchema(configSchemaPath: ?Uri): Promise<?GraphQLSchema> {
    if (!configSchemaPath) {
      return null;
    }
    const schemaPath = path.join(this._configDir, configSchemaPath);
    if (this._schemaMap.has(schemaPath)) {
      return this._schemaMap.get(schemaPath);
    }

    const schemaDSL = await new Promise(resolve =>
      fs.readFile(schemaPath, 'utf8', (error, content) => {
        if (error) {
          throw new Error(error);
        }
        resolve(content);
      }),
    );

    const schemaFileExt = path.extname(schemaPath);
    let schema;
    try {
      switch (schemaFileExt) {
        case '.graphql':
          schema = buildSchema(schemaDSL);
          break;
        case '.json':
          schema = buildClientSchema(JSON.parse(schemaDSL));
          break;
        default:
          throw new Error('Unsupported schema file extention');
      }
    } catch (error) {
      throw new Error(error);
    }

    this._schemaMap.set(schemaPath, schema);
    return schema;
  }