-
-
Notifications
You must be signed in to change notification settings - Fork 565
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 extensions utility? #180
Comments
That would be nice, but it's unlikely we'll port it soon (too little time now). So PRs are welcome! |
Hello guys, I already have the code ported along with a merging/stitching function taken from Apollo. It's not 100 percent as they keep pushing more features but I can drop it on a repository so you can play with it and maybe help polishing the code |
It work this way in The What do you think, if we follow a slightly different approach: We can add the support of extensions into For example: RootSchema.graphqls schema {
query: Query
}
type Query {
version: String
} UsersSchema.graphqls type User {
name: String
}
extend type Query {
users: [User]
} Then, all we need is to concatenate them into result schema and pass to $schemaSources = [
file_get_contents("RootSchema.graphqls"),
file_get_contents("UsersSchema.graphqls")
];
$schema = BuildSchema::build(implode("\n\n", $schemaSources)); This feature will require less time, comparing to developing new utility. Also there are a lot of useful private methods in And, yes, I can create a pull request, if you guys don't mind this feature? Related discussion in |
@crirus |
@greyexpert here is the initial code, any questions let me know |
It has been ported into https://github.com/webonyx/graphql-php/blob/master/src/Utils/SchemaExtender.php |
@vladar I'm sorry but I don't really get it. How is it supposed to be used? The class isn't referenced anywhere in the code and it has no public methods. Is it supposed to be extended? If so, why isn't it Edit: I'm an idiot. I didn't see the |
@vladar I'm sorry if this is a dumb question, but is this supposed to somehow combine the two schema files type Person {
name: String!
} type Person {
age: Int!
} into one type Person {
name: String!
age: Int!
} Because that's exactly what I would need. |
@Torsten85 Can you please clarify as you are the one ported this utility? |
it should be used exactly like the graphql-js counterpart (https://github.com/graphql/graphql-js/blob/master/src/utilities/extendSchema.js#L103). Small example: $sdl = '
type Query {
defaultValue: String
}
';
$documentNode = \GraphQL\Language\Parser::parse($sdl);
$schema = \GraphQL\Utils\BuildSchema::build($documentNode);
$extensionSdl = '
extend type Query {
extendendValue: String
}
';
$extendedDocumentNode = \GraphQL\Language\Parser::parse($extensionSdl);
$extendedScheam = \GraphQL\Utils\SchemaExtender::extend($schema, $extendedDocumentNode);
echo \GraphQL\Utils\SchemaPrinter::doPrint($extendedScheam); this will echo:
|
Is the following supposed to work? $sdl = '
type Query {
defaultValue: String
}
type Foo {
value: Int
}
';
$documentNode = \GraphQL\Language\Parser::parse($sdl);
$schema = \GraphQL\Utils\BuildSchema::build($documentNode);
$extensionSdl = '
type Bar {
foo: Foo
}
';
$extendedDocumentNode = \GraphQL\Language\Parser::parse($extensionSdl);
$extendedScheam = \GraphQL\Utils\SchemaExtender::extend($schema, $extendedDocumentNode);
echo \GraphQL\Utils\SchemaPrinter::doPrint($extendedScheam); I get a |
@MidnightDesign you are completely right, this should work! (https://codesandbox.io/s/yjmpnop8k9) I've digged a little deeper and found a "bug" in my implementation. This PR should fix this: #417 |
Hello there,
Do you have any plans of porting
extendSchema
utility fromgraphql-js
?https://github.com/graphql/graphql-js/blob/master/src/utilities/extendSchema.js
It would be great to have ability to build modular schema and to extend type definitions using
The text was updated successfully, but these errors were encountered: