Skip to content

Commit

Permalink
chore(graphql): add linter to ensure docstrings on graphene graphql o…
Browse files Browse the repository at this point in the history
…bjects (#7669)
  • Loading branch information
rexledesma committed May 3, 2022
1 parent 636decb commit e9dd228
Show file tree
Hide file tree
Showing 51 changed files with 454 additions and 4 deletions.
381 changes: 381 additions & 0 deletions js_modules/dagit/packages/core/src/graphql/schema.graphql

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions js_modules/dagit/packages/core/src/scripts/generateGraphQLTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ console.log('Downloading schema...');
const TARGET_FILE = './src/graphql/schema.graphql';

// https://github.com/dagster-io/dagster/issues/2623
// Initially, write schema.graphql in the SDL format, without descriptions
// Otherwise, the generated types in Typescript would also have descriptions.
const result = execSync(
`dagster-graphql --ephemeral-instance --empty-workspace -t '${getIntrospectionQuery({
descriptions: false,
})}'`,
{cwd: '../../../../examples/docs_snippets/'},
).toString();

const schemaJson = JSON.parse(result).data;

// Write schema.graphql in the SDL format
const sdl = printSchema(buildClientSchema(schemaJson));

console.log('Generating schema.graphql...');
console.log('Generating schema.graphql without descriptions...');

writeFileSync(TARGET_FILE, sdl);

Expand All @@ -45,6 +44,19 @@ execSync(
{stdio: 'inherit'},
);

// https://github.com/dagster-io/dagster/issues/2623
// Finally, write schema.graphql in the SDL format, with descriptions
const resultWithDescriptions = execSync(
`dagster-graphql --ephemeral-instance --empty-workspace -t '${getIntrospectionQuery()}'`,
{cwd: '../../../../examples/docs_snippets/'},
).toString();
const schemaJsonWithDescriptions = JSON.parse(resultWithDescriptions).data;
const sdlWithDescriptions = printSchema(buildClientSchema(schemaJsonWithDescriptions));

console.log('Generating schema.graphql with descriptions...');

writeFileSync(TARGET_FILE, sdlWithDescriptions);

execSync(`yarn prettier --loglevel silent --write ${TARGET_FILE}`, {stdio: 'inherit'});

console.log('Done!');
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
from typing import TYPE_CHECKING, List, Optional, Sequence, Union

import graphene
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from .util import non_null_list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from .config_types import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
from dagster_graphql.implementation.events import iterate_metadata_entries
from dagster_graphql.schema.metadata import GrapheneMetadataEntry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
from dagster_graphql.implementation.fetch_runs import (
get_in_progress_runs_by_step,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
import pendulum

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import sys

import graphene
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import sys
import warnings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import logging

import graphene
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from .asset_key import GrapheneAssetKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
from dagster_graphql.implementation.fetch_partition_sets import (
get_partition_by_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
from collections import namedtuple

import graphene
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from ..errors import GraphenePipelineNotFoundError, GraphenePythonError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
import yaml

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from ..logs.events import GrapheneDagsterRunEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from ..errors import GrapheneAssetNotFoundError, GraphenePythonError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from ..errors import GraphenePipelineNotFoundError, GraphenePythonError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from ..errors import GrapheneGraphNotFoundError, GraphenePipelineNotFoundError, GraphenePythonError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import json

import graphene
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster import check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
from dagster_graphql.implementation.loader import RepositoryScopedBatchLoader

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from dagster.core.scheduler.instigation import TickStatus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene
from dagster_graphql.implementation.loader import RepositoryScopedBatchLoader
from dagster_graphql.implementation.utils import capture_error, check_permission
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
from functools import lru_cache

import graphene
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from .util import non_null_list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from .util import non_null_list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-graphene-docstring
import graphene

from .pipelines.pipeline import GraphenePipeline
Expand Down
9 changes: 9 additions & 0 deletions python_modules/dagster/dagster/utils/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class DagsterChecker(BaseChecker):
"pendulum datetime"
),
),
"W0005": (
"Graphene object without docstring",
"missing-graphene-docstring",
"A docstring must be written for Graphene GraphQL object",
),
}
options = ()

Expand Down Expand Up @@ -92,6 +97,10 @@ def visit_call(self, node):
):
self.add_message("pendulum-in-tz", node=node)

def visit_classdef(self, node):
if any(n for n in node.basenames if "graphene" in n) and not node.doc_node:
self.add_message("missing-graphene-docstring", node=node)


def register_solid_transform():
def _is_solid_or_op(node):
Expand Down

0 comments on commit e9dd228

Please sign in to comment.