t3n / graphql Goto Github PK
View Code? Open in Web Editor NEWFlow Package to add graphql APIs to Neos and Flow that also supports some advanced features
License: MIT License
Flow Package to add graphql APIs to Neos and Flow that also supports some advanced features
License: MIT License
As far as I can see – and I tried and played with this for a couple of hours – interfaces are not yet supported.
My concrete use case is implementing the server specification for Relay, which enables me to provide cursor-based pagination and universal object identification.
Given the following minimal GraphQL schema:
interface Node {
id: ID!
}
type CustomerAccount implements Node {
id: ID!
customerName: String!
}
type Query {
node(
id: ID!
): Node
}
When I submit any query, I will receive an exception:
Type "Node" is missing a "__resolveType" resolver.
Pass false into "resolverValidationOptions.requireResolversForResolveType" to disable this warning.
GraphQLTools\Generate\SchemaError
Packages/Libraries/t3n/graphql-tools/src/Generate/CheckForResolveTypeResolver.php 34
Just for good measure, I tried setting that validation option to false, but there is currently no way to do that in the Flow package (it is possible programmatically in the GraphQLTools package).
To fix this, we need a way to provide a custom resolveType
function. Ideally, Flow would automatically recognize such a function in my Resolver class.
I temporarily solved the first problem by hardcoding the resolve type as follows:
namespace GraphQLTools\Generate;
…
class CheckForResolveTypeResolver
{
/**
* @throws SchemaError
*/
public static function invoke(Schema $schema, ?bool $requireResolversForResolveType = null) : void
{
/**
* @var UnionType|InterfaceType $typeName
*/
foreach ($schema->getTypeMap() as $typeName => $type) {
if (! ($type instanceof UnionType || $type instanceof InterfaceType)) {
continue;
}
if (!isset($type->config['resolveType'])) {
$type->config['resolveType'] = function () {
return 'CustomerAccount';
};
}
…
}
}
}
Now the schema warning is gone.
When I try to query a node as follows:
query Query {
node(id: "1234") {
id
}
}
I receive a inexpressive error:
{
"errors":
[
{"message":"Internal server error",
"extensions":
{"category":"internal"},
"locations":[
{"line":2,"column":5}
],
"path":["node"]}
],
"data":{"node":null}
}
In the resolver, I tried solving the issue by returning different kinds of data. Among them, a CustomerAccount
class (which supports JsonSerialize), an array based on CustomerAccount, a literal, an array with just an id:
/**
* @param $_
* @param array $arguments
*/
public function node($_, array $arguments)
{
return [
'id' => '1234'
];
}
I'm a bit clueless about what the correct data would be to return in the query function.
When using the DefaultFieldResolver
there is the following risk:
Resolving an object through the "magic" ObjectAccess returning a property value that is callable, the resolver will call this function.
if (is_object($source) && ObjectAccess::isPropertyGettable($source, $fieldName)) {
$resolvedProperty = ObjectAccess::getProperty($source, $fieldName);
}
if (is_callable($resolvedProperty)) {
return $resolvedProperty($source, $args, $context, $info);
}
I noticed this when working with a user with firstName
"Max". I do not have a specific resolver for User
.
So, first the DefaultFieldResolver
gets the firstName
property from the User
object through ObjectAccess::getProperty
and assignes $resolvedProperty = 'Max'
. Since Max
is callable, this is executed.
This is quite risky when working with user input. Possibly only support Closures here?
When sending a request that has an Accept: application/json
header set, requests return a 406 Not Acceptable
.
Reason: GraphQLController
extends ActionController
extends AbstractController
, which contains protected $supportedMediaTypes = ['text/html'];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.