Skip to content

Commit

Permalink
Revert "Read service gqlgen.yml file to find a list of related graphq…
Browse files Browse the repository at this point in the history
…l schemas"

This reverts commit fd2d0e4.

Auditors: marksandstrom
  • Loading branch information
dkapadia committed Apr 10, 2020
1 parent fd2d0e4 commit 748f6ec
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Linters process files or lists of files for correctness."""

import itertools
import glob
import json
import logging
import os
Expand Down Expand Up @@ -839,10 +840,11 @@ def process(self, f, contents_of_f):
# https://github.com/cjoudrey/graphql-schema-linter/issues/210
#
# So instead we take a two-pronged approach:
# 1) We find the `gqlgen.yml` file that belongs to this service and
# parse it to find out all the other schema files the service depends
# on. This matches what gqlgen does, and will not have the @extends
# problem since it's only for a single backend.
# 1) We append all the other schema files in our directory.
# This matches what gqlgen does, and will not have the
# @extends problem since it's only for a single backend.
# TODO(csilvers): read gqlgen.yml to figure out what
# schema files to include, instead of glob.
# 2) We then try to run the linter and catch all "undefined
# type" errors. We then add fake definitions for those
# types, and re-run the linter.
Expand All @@ -859,22 +861,12 @@ def process(self, f, contents_of_f):
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
directive @extends on OBJECT | INTERFACE
"""
# All schema files should live at the top level of a service, so we can
# look for the current gqlgen.yml
service_root = os.path.dirname(f)
gqlgen_path = os.path.join(service_root, "gqlgen.yml")
try:
gqlgen_contents = yaml.safe_load(self._read_file(gqlgen_path))
schema_files = [
os.path.join(service_root, schema_file)
for schema_file in gqlgen_contents["schema"]]
except Exception:
# If the gqlgen.yml file doesn't exist (for shared schemas) we
# assume there are no related files we need.
schema_files = []
# Khan-specific directives
directive @migrate(from: String!, state: String!) on FIELD_DEFINITION
"""

schema_files = glob.glob(os.path.join(os.path.dirname(f), '*.graphql'))
for other_f in schema_files:
if other_f == f:
continue
Expand Down

0 comments on commit 748f6ec

Please sign in to comment.