GithubHelp home page GithubHelp logo

t3n / graphql Goto Github PK

View Code? Open in Web Editor NEW
15.0 12.0 8.0 106 KB

Flow Package to add graphql APIs to Neos and Flow that also supports some advanced features

License: MIT License

PHP 100.00%
neoscms graphql php flowframework flowpackage

graphql's People

Contributors

johannessteu avatar kdambekalns avatar pmaas avatar robertlemke avatar sebobo avatar simstern avatar torsten85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql's Issues

GraphQL service does not support interfaces

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
}

resolveType

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.

internal error in response

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.

DefaultFieldResolver: callback through ObjectAccess vulnerability

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?

Requests with Accept header end in 406

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'];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.