in src/services/graphqlService.ts [28:85]
public async getGraphqlTypesAndSchema(apiName: string): Promise<{graphqlTypes: TGraphqlTypes, schema: string}> {
const api = await this.apiService.getApi(`apis/${apiName}`);
const graphqlTypes: TGraphqlTypes = {
query: {},
mutation: {},
subscription: {},
objectType: {},
inputObjectType: {},
enumType: {},
scalarType: {},
unionType: {},
interfaceType: {}
};
if (api?.type === TypeOfApi.graphQL) {
const graphQLSchema = await this.apiService.getGQLSchema(api.id);
if (!graphQLSchema) {
return;
}
const schema = graphQLSchema.graphQLSchema;
const builtSchema = GraphQL.buildSchema(graphQLSchema.graphQLSchema, { commentDescriptions: true });
graphqlTypes.query = builtSchema.getQueryType()?.getFields();
graphqlTypes.mutation = builtSchema.getMutationType()?.getFields();
graphqlTypes.subscription = builtSchema.getSubscriptionType()?.getFields();
const typeMap = builtSchema.getTypeMap();
graphqlTypes.objectType = _.pickBy(typeMap, (t) => {
return (t instanceof GraphQL.GraphQLObjectType);
});
graphqlTypes.inputObjectType = _.pickBy(typeMap, (t) => {
return (t instanceof GraphQL.GraphQLInputObjectType);
});
graphqlTypes.enumType = _.pickBy(typeMap, (t) => {
return (t instanceof GraphQL.GraphQLEnumType);
});
graphqlTypes.scalarType = _.pickBy(typeMap, (t) => {
return (t instanceof GraphQL.GraphQLScalarType);
});
graphqlTypes.unionType = _.pickBy(typeMap, (t) => {
return (t instanceof GraphQL.GraphQLUnionType);
});
graphqlTypes.interfaceType = _.pickBy(typeMap, (t) => {
return (t instanceof GraphQL.GraphQLInterfaceType);
});
_.forEach(graphqlTypes, (value, key) => {
const valueData = value;
this.addingNewFields(valueData, key);
if (key == GraphqlTypes.query || key == GraphqlTypes.subscription || key == GraphqlTypes.mutation) {
value = this.sortingAlphabetically(valueData);
}
graphqlTypes[key] = value;
});
return { graphqlTypes, schema };
}
}