SWAPI example: construct schema from SDL#1384
Conversation
| episodeEnum.getValue('JEDI').value = 6; | ||
| for (const enumValue of episodeEnum.getValues()) { | ||
| episodeEnum._valueLookup.set(enumValue.value, enumValue); | ||
| } |
There was a problem hiding this comment.
There no way to assign enum values after schema constructed.
@leebyron What do you this about adding one more option to buidlSchema/extendSchema?
const schema = buildSchema(sdl, {
extraConfig: {
types: {
Episode: {
values: {
NEWHOPE: { value: 4 },
EMPIRE: { value: 5 },
JEDI: { value: 6 },
},
},
},
},
});There was a problem hiding this comment.
Likewise buildSchema does not provide resolvers or resolveType functions - I think this is probably more appropriate for the graphql-tools which provides additional runtime behavior atop buildSchema
There was a problem hiding this comment.
I'm implementing this in #1987, it may look like:
const schema = buildSchema(sdl, {
resolvers: {
Episode: {
NEWHOPE: 4,
EMPIRE: 5,
JEDI: 6,
},
},
});if merged of course :-)
See this test:
graphql-js/src/utilities/__tests__/buildASTSchema-test.js
Lines 98 to 123 in 84adacf
leebyron
left a comment
There was a problem hiding this comment.
I'm not sure this is something we want to do - this is supposed to act as both an example of and full integration test of the schema definition API and query path.
| it('Allows us to query for Luke Skywalker directly, using his ID', async () => { | ||
| const query = ` | ||
| query FetchLukeQuery { | ||
| const result = await executeQuery(` |
There was a problem hiding this comment.
These are intended to be full integration tests, so they intentionally were running the full graphql function instead of just the execute step
There was a problem hiding this comment.
@leebyron it's a naming issue executeQuery is defined like this:
function executeQuery(query, variableValues) {
return graphql(StarWarsSchema, query, new Query(), null, variableValues);
}Since now in majority of tests you need to supply 3 args instead of 2:
const result = graphql(StarWarsSchema, query, new Query());I decided to move it into utility function but now I see that it needs a better name. Do you have any suggestions?
| friends: Array<string>, | ||
| appearsIn: Array<number>, | ||
| }; | ||
| export type CharacterData = HumanData | DroidData; |
There was a problem hiding this comment.
I prefer without the Data suffix for readability
There was a problem hiding this comment.
No please, because of:
@leebyron Agree 👍 I got carried away with shiny SDL syntax, P.S. This PR is not a part of |
|
so these codes for v15?? |
|
Closing this old PR, feel free to reopen! We can track efforts to build a |
Add `supplementalConfig` to `buildSchema`, `buildASTSchema`, and `extendSchema` so SDL-defined schema elements can receive constructor-only configuration that SDL cannot express. The option is validated by default and can be bypassed with `assumeValidSupplementalConfig` for config that has already been checked. The schema-level config is keyed by schema element kind and GraphQL name: - `scalarTypes`: `serialize`, `parseValue`, `parseLiteral`, `coerceOutputValue`, `coerceInputValue`, `coerceInputLiteral`, `valueToLiteral`, and `extensions`. - `objectTypes`: `fields`, `isTypeOf`, and `extensions`. - `interfaceTypes`: `fields`, `resolveType`, and `extensions`. - `unionTypes`: `resolveType` and `extensions`. - `enumTypes`: `values` and `extensions`; enum values can define an internal `value` and `extensions`. - `inputObjectTypes`: `fields` and `extensions`. - `directives`: `args` and `extensions`. - `extensions`: schema extensions. Field supplements can be a resolver function or an object with `resolve`, `subscribe`, `args`, and `extensions`. Argument, input field, directive argument, enum value, and type supplements apply only to schema elements declared or extended by the SDL document, and unmatched supplemental config is rejected by default. This lets SDL own the type-system shape while JavaScript supplies runtime behavior and host-language metadata: field resolvers, subscription functions, abstract type resolution, object type predicates, custom scalar coercion and literal conversion, enum runtime values, and extensions. Related issues: graphql#497, graphql#499, graphql#516, graphql#525, graphql#604, graphql#622, graphql#1379, graphql#1858. Related prior PRs: graphql#469, graphql#947, graphql#1384, graphql#1987.
Add `supplementalConfig` to `buildSchema`, `buildASTSchema`, and `extendSchema` so SDL-defined schema elements can receive constructor-only configuration that SDL cannot express. The option is validated by default and can be bypassed with `assumeValidSupplementalConfig` for config that has already been checked. The schema-level config is keyed by schema element kind and GraphQL name: - `scalarTypes`: `serialize`, `parseValue`, `parseLiteral`, `coerceOutputValue`, `coerceInputValue`, `coerceInputLiteral`, `valueToLiteral`, and `extensions`. - `objectTypes`: `fields`, `isTypeOf`, and `extensions`. - `interfaceTypes`: `fields`, `resolveType`, and `extensions`. - `unionTypes`: `resolveType` and `extensions`. - `enumTypes`: `values` and `extensions`; enum values can define an internal `value` and `extensions`. - `inputObjectTypes`: `fields` and `extensions`. - `directives`: `args` and `extensions`. - `extensions`: schema extensions. Field supplements can be a resolver function or an object with `resolve`, `subscribe`, `args`, and `extensions`. Argument, input field, directive argument, enum value, and type supplements apply only to schema elements declared or extended by the SDL document, and unmatched supplemental config is rejected by default. This lets SDL own the type-system shape while JavaScript supplies runtime behavior and host-language metadata: field resolvers, subscription functions, abstract type resolution, object type predicates, custom scalar coercion and literal conversion, enum runtime values, and extensions. Related issues: graphql#497, graphql#499, graphql#516, graphql#525, graphql#604, graphql#622, graphql#1379, graphql#1858. Related prior PRs: graphql#469, graphql#947, graphql#1384, graphql#1987.
Add `supplementalConfig` to `buildSchema`, `buildASTSchema`, and `extendSchema` so SDL-defined schema elements can receive constructor-only configuration that SDL cannot express. The option is validated by default and can be bypassed with `assumeValidSupplementalConfig` for config that has already been checked. The schema-level config is keyed by schema element kind and GraphQL name: - `scalarTypes`: `serialize`, `parseValue`, `parseLiteral`, `coerceOutputValue`, `coerceInputValue`, `coerceInputLiteral`, `valueToLiteral`, and `extensions`. - `objectTypes`: `fields`, `isTypeOf`, and `extensions`. - `interfaceTypes`: `fields`, `resolveType`, and `extensions`. - `unionTypes`: `resolveType` and `extensions`. - `enumTypes`: `values` and `extensions`; enum values can define an internal `value` and `extensions`. - `inputObjectTypes`: `fields` and `extensions`. - `directives`: `args` and `extensions`. - `extensions`: schema extensions. Field supplements can be a resolver function or an object with `resolve`, `subscribe`, `args`, and `extensions`. Argument, input field, directive argument, enum value, and type supplements apply only to schema elements declared or extended by the SDL document, and unmatched supplemental config is rejected by default. This lets SDL own the type-system shape while JavaScript supplies runtime behavior and host-language metadata: field resolvers, subscription functions, abstract type resolution, object type predicates, custom scalar coercion and literal conversion, enum runtime values, and extensions. Related issues: graphql#497, graphql#499, graphql#516, graphql#525, graphql#604, graphql#622, graphql#1379, graphql#1858. Related prior PRs: graphql#469, graphql#947, graphql#1384, graphql#1987.
Motivation #1379