Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Definition Language Parser #74

Merged
merged 1 commit into from Jul 21, 2015
Merged

Schema Definition Language Parser #74

merged 1 commit into from Jul 21, 2015

Conversation

schrockn-zz
Copy link
Contributor

This is a parser for the ad-hoc type definition language included in the
spec. This should also serve as a de-facto spec for the language.
Clearly once this is stable we should include it in the actual spec as
well.

This should end up being useful in a few contexts, including
client-side types and also a DSL for producing the JS type definitions
which can be tedious to write, and a way to specify acceptance tests.
(This would be a clear next step for this project)

@@ -242,3 +242,52 @@ export type NonNullType = {
loc?: ?Location;
type: NamedType | ListType;
}

export type TypeDefinition = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably go into another file, clientAST.js or something like that.

@leebyron
Copy link
Contributor

This all seems pretty solid to me.

I think there's just some relatively minor code isolation issues to fix up, perhaps moving most of this stuff into language/schema/*.js rather than altering individual files.

I also think you can terse up the parser a bit by putting the parse steps inline in the object definition - that pattern is pretty pervasive through the current parser.

@leebyron
Copy link
Contributor

One higher-level question is how this relates to client parsers (read: FB's graphql-data) which interleave GraphQL query and GraphQL schema for the purposes of code-generation, and isolate fragments into separate files and need to refer to them in some way.

It seems like either this schema should be merged with that use case, or there is a 3rd variety of parser we will want to eventually support.

@schrockn-zz
Copy link
Contributor Author

re: your last comment definitely a third type with interleaving IMO

unexpected,
expectKeyword,
advance,
} from './parserCore';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The role of this is a little muddy. I wonder if there's a better place for parseName and the parseType group to exist? They're definitely specific parser rules not parser core functionality.

For the short term, and for the sake of maintaining the clarity of this document relative to the spec, I would suggest (deep breath) copying these few functions directly in schema/parser.js. I think DRY is working against us here.

@@ -597,13 +425,24 @@ function parseDirective(parser): Directive {
};
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remain in current position

};
}

function parseSchemaDocument(parser): SchemaDocument {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in terms of ease of reading this file, I'd suggest moving this fn between parseSchema and parseNextSchemaDefinition (which I may also suggest naming just parseSchemaDefinition).

I'd also suggest organizing the functions to be in the same order as they're listed within the switch statement in parseNextSchemaDefinition

@schrockn-zz schrockn-zz force-pushed the schema-dsl branch 2 times, most recently from f6902c2 to 47a9168 Compare July 21, 2015 01:23
NON_NULL_TYPE,
LIST_TYPE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@schrockn-zz schrockn-zz force-pushed the schema-dsl branch 3 times, most recently from 89eba2f to 51b593a Compare July 21, 2015 01:44
This is a parser for the ad-hoc type definition language included in the
spec. This should also serve as a de-facto spec for the language.
Clearly once this is stable we should include it in the actual spec as
well.

This should end up being useful in a few contexts, including
client-side types and also a DSL for producing the JS type definitions
which can be tedious to write, and a way to specify acceptance tests.
(This would be a clear next step for this project)
schrockn-zz added a commit that referenced this pull request Jul 21, 2015
Schema Definition Language Parser

This is a parser for the ad-hoc type definition language included in the
spec. This should also serve as a de-facto spec for the language.
Clearly once this is stable we should include it in the actual spec as
well.

This should end up being useful in a few contexts, including
client-side types and also a DSL for producing the JS type definitions
which can be tedious to write, and a way to specify acceptance tests.
(This would be a clear next step for this project)
@schrockn-zz schrockn-zz merged commit 8727a08 into master Jul 21, 2015
@leebyron leebyron deleted the schema-dsl branch July 21, 2015 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants