Code Monkey home page Code Monkey logo

sailor's People

Contributors

crc-mismatch avatar ralf77 avatar refo avatar simbig avatar simpod avatar spawnia avatar vuongxuongminh avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sailor's Issues

ObjectLike properties array causing Errors for missing array keys

I'm not sure exactly the best place to have this discussion, as it's not directly a change request (bug or feature), though it may lead to a change.

With the new ObjectLike class created in https://github.com/spawnia/sailor/pull/43/files#diff-6c63d1f76bf76e60d9171ee92df465a000e305de36f1f9451e8e77075a7da510, I started getting errors from my mocked objects after an update, because previously for nullable things I just wasn't setting those properties in my mock response and letting them stay the default. However, that now throws an Exception in the __get magic method because it attempts to retrieve an array key that isn't defined.

Could you explain why you made that change? I could be using this library incorrectly somehow, as I wouldn't expect it to matter whether the value was explicitly passed as null or simply not passed at all. If anything, if the server doesn't respond with a field you requested, I think that should be treated as a problem in the server implementation and probably throw a parse exception from the response, not error when you try to access the field.

Custom scalar type not convert type when use it as an argument

Describe the bug

With datetime type config:

class DateTimeTypeConfig implements TypeConfigInterface
{
    public function typeConverter(): string
    {
        return DateTimeTypeConverter::class;
    }

    public function typeReference(): string
    {
        return \DateTimeInterface::class;
    }

    public function generateClasses(): iterable
    {
        return [];
    }
}

Converter:

class DateTimeTypeConverter implements TypeConverterInterface
{
    public function fromGraphQL($value)
    {
        try {
            $dateTime = \DateTimeImmutable::createFromFormat(DATE_ISO8601, $value);
        } catch (\Throwable) {
            $dateTime = false;
        }

        if (false === $dateTime) {
            throw new \InvalidArgumentException(
                sprintf('Expected string with format `%s`, got %s', DATE_ISO8601, gettype($value))
            );
        }

        return $dateTime;
    }

    public function toGraphQL($value)
    {
        if (!$value instanceof \DateTimeInterface) {
            throw new \InvalidArgumentException(
                sprintf('Expected instance of %s, got %s', \DateTimeInterface::class, gettype($value))
            );
        }

        return $value->format(DATE_ISO8601);
    }
}

and operation:

query Merchants($beginDate: datetime) {
    merchants(where: {created_at: {_gt: $beginDate}}) {
        id
    }
}

Expected behavior/Solution

When execute method Merchants::execute(new \DateTime('2021-12-21')); datetime input arg should be convert to DATE_ISO8601 string but currently it send serialized datetime object.

Support fragments

Using GraphQL fragment in query currently results in error

Found unsupported definition in /src/myQuery.graphql

query MyQuery {
	listDocument {
		...documentFields
	}
}

fragment documentFields on Document {
	id
	title
}

Exclude vendor directory in Finder

Describe the bug

When an endpoint is configured to look for files in the project root, .graphql files within the vendor directory are included.

Expected behavior/Solution

The contents of vendor should be excluded.

Support unions

Is your feature request related to a problem? Please describe.

Querying unions is not supported.

Describe the solution you'd like

Proper code generation of result classes that map to the polymorphic result.

guzzle/guzzle dependency issue

Running composer require guzzle/guzzle results in an uninstallable set of dependencies

(composer output in the output/logs below)

Steps to reproduce

  1. make a new project
  2. composer require spawnia/sailor
  3. composer require guzzle/guzzle

Output/Logs

Click to expand
composer require --dev guzzle/guzzle
Using version ^3.9 for guzzle/guzzle
./composer.json has been updated
Running composer update guzzle/guzzle
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - guzzle/guzzle[v3.9.0, ..., v3.9.3] require symfony/event-dispatcher ~2.1 -> satisfiable by symfony/event-dispatcher[v2.1.0, ..., v2.8.52].
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.52.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.50.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.49.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.48.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.47.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.46.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.45.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.44.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.43.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.42.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.41.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.40.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.39.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.38.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.37.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.36.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.35.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.34.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.33.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.32.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.31.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.30.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.29.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.28.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.27.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.26.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.25.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.24.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.23.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.22.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.21.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.20.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.19.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.18.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.17.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.16.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.15.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.14.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.13.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.12.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.8.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.51.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.50.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.49.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.48.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.47.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.46.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.45.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.44.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.43.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.42.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.41.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.40.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.39.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.38.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.37.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.36.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.35.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.34.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.33.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.32.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.31.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.30.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.29.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.28.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.27.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.26.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.25.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.24.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.23.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.22.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.21.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.20.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.19.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.18.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.17.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.16.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.15.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.14.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.13.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.12.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.7.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.13.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.12.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.6.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.12.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.5.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.4.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.42.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.41.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.40.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.39.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.38.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.37.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.36.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.35.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.34.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.33.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.32.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.31.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.30.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.29.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.28.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.27.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.26.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.25.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.24.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.23.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.22.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.21.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.20.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.19.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.18.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.17.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.16.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.15.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.14.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.13.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.12.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.3.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.2.0.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.13.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.12.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.11.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.10.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.9.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.8.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.7.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.6.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.5.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.4.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.3.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.2.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.1.
    - symfony/console v5.3.10 conflicts with symfony/event-dispatcher v2.1.0.
    - spawnia/sailor v0.10.2 requires symfony/console ^5 -> satisfiable by symfony/console[v5.3.10].
    - spawnia/sailor is locked to version v0.10.2 and an update of this package was not requested.
    - Root composer.json requires guzzle/guzzle ^3.9 -> satisfiable by guzzle/guzzle[v3.9.0, v3.9.1, v3.9.2, v3.9.3].


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Guzzle getBody with dynamic clients throws error

Guzzle version 7+ cannot get body after it has already been accessed guzzle/guzzle#2452
When using https://github.com/spawnia/sailor#dynamic-clients the client's response can be accessed (for example by Guzzle middleware https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html) and it breaks the Sailor implementation of Guzzle response with getBody with this error:

An uncaught Exception was encountered

Type: Spawnia\Sailor\Error\InvalidDataException

Message: Received a response that is invalid JSON:

Filename: /var/www/html/vendor/spawnia/sailor/src/Response.php

Line Number: 59

Backtrace:

File: /var/www/html/vendor/spawnia/sailor/src/Response.php
Line: 43
Function: fromJson

File: /var/www/html/vendor/spawnia/sailor/src/Client/Guzzle.php
Line: 33
Function: fromResponseInterface

File: /var/www/html/vendor/spawnia/sailor/src/Operation.php
Line: 87
Function: request

File: /var/www/html/vendor/spawnia/sailor/src/Operation.php
Line: 59
Function: fetchResponse 

One solution may be to use __toString instead of getBody

Branch with v15 support

Hi, can we create a branch where support for graphql-php v15 will be developed? I'd like to test this lib on lastest graphql-php master.

Directive.isRepeatable is not present

Describe the bug

Introspector calls BuildClientSchema::build() which requires directive to contain isRepeatable info

        return new Directive([
            'name' => $directive['name'],
            'description' => $directive['description'],
            'args' => $this->buildInputValueDefMap($directive['args']),
            'isRepeatable' => $directive['isRepeatable'],
            'locations' => $directive['locations'],
        ]);

graphql-php v14.5.1

[Support] - date range

Hello,

I wonder how to implement this query with Sailor (a date range query base on an input that is built up incrementally) :

query MyQuery {
  molecule(where: {mol_weight: {_gte: "", _lte: ""}}) {
    id
    mol_weight
  }
}

In my case, "mol_weight" type is "numeric_comparison_exp".

I wish i could do this:

$exp = new ...\molecule_bool_exp();
$exp->mol_weight = "define_my_interval_here";

Many thanks in advance.

Eric

Async operations

Is your feature request related to a problem? Please describe.

I'm loading several pages from graphql api and need to do it asynchronously in order to make it faster

Describe the solution you'd like

Still am not sure. Investigating, though it seems it would need a large rework.


I'm calling gql api using PSR Request through async client. Trying to do the same with Sailor is not possible rn.

E.g. Symfony HTTP client has async requests by default but Response makes it blocking since it reads status code and contents right after calling client.

sailor/src/Response.php

Lines 38 to 47 in 44678a8

public static function fromResponseInterface(ResponseInterface $response): self
{
if ($response->getStatusCode() !== 200) {
throw new InvalidResponseException("Response must have status code 200, got: {$response->getStatusCode()}");
}
return self::fromJson(
$response->getBody()->getContents()
);
}

nette/php-generator should be in require-dev

Generating PHP code should not be used in prod, only in dev. The same is for symfony/console. Maybe other libs that are in required are used for code gen only, they need to go to dev too.

Allow to introspect but not generate classes

I'm using IDE gql plugin to generate schema definitions. However, Sailor does this better.

I'd like to use sailor for introspection only in some cases. That said to be able to run introspect but not to generate classes.

I propose to introduce SchemaConfig class.

Generate class from schema.graphql

Hello,

Many thanks for Sailor library.

I would think that this lib could generated class directly from the schema.graphql file that is generated during introspection.

But i understand i do need to write each graphql queries and mutations for the PHP class to be generated (configuration file need a path to look for .graphql files containing operations ).

Is there a way to generate all queries and mutations classes from a schema.json file or the generated schema.graphql ?

Many thanks in advance

ps : I think i have to tell that i am using Hasura, so i wonder if i can use the auto-generated queries : https://hasura.io/docs/latest/graphql/core/databases/postgres/mutations/insert.html#auto-generated-insert-mutation-schema

GraphQL custom scalar types should be type hint `mixed` in PHP

Is your feature request related to a problem? Please describe.

My GraphQL server define custom scalar type json's an array like an example at https://graphql.org/learn/schema/#scalar-types but currently generator generate executor method args with PHP type hint's string so I can not pass an array arg to executor.

Example with graphql operation:

query CheckPermissions($userId: Int!, $permissions: json!) {
    permissions_check(permissions: $permissions, user_id: $userId)
}

Will generate an executor method:

    public static function execute(int $userId, string $permissions): CheckPermissions\CheckPermissionsResult
    {
        return self::executeOperation(...func_get_args());
    }

Describe the solution you'd like

In my case above, $permissions should be type hint with mixed type so I can pass an array to it.

For custom scalar types, I think Spawnia\Sailor\Codegen\PhpType::forScalar method should be return mixed type for PHP8 and above and return empty string (mixed too) for lower PHP versions.

Allow setting HTTP headers per request

Is your feature request related to a problem? Please describe.
Currently there is no way to set headers as part of the request, they can only be done as part of the client config, so any dynamic header, including authorisation is impossible unless i'm missing something?

Describe the solution you'd like
Along with variables (or as part of them?) be able to set http headers on the client at the point of making the request

Describe alternatives you've considered
Injecting a dynamic client, but some things are request dependant so it didnt really work.

Im happy to pull something together for it if you think its something that would be included?

postgresql float8 is handle by Scalar_converter and return excetion

Hello,

I hope i will not waste time of anyone. I do not think it is a bug, i think i missed something in my side.

I noticed that the fields defined as float8 in postgres are handle by ScalarConverter, and then ScalarConverter return exception as my value is float/decimal but not string.

Just to realize what happens i modify ScalaConverter like this:

    public function fromGraphQL($value): string
    {
        if (! is_string($value) && (!is_float($value)) ) {
            $value = (string) $value;
            // throw new \InvalidArgumentException('Expected string, got ' . gettype($value));
        }

        return $value;
    }

And then it is ok, (value in this case is 100, not 100.00).

Many thanks in advance for reading.

Eric

Support interfaces

I'm trying to generate classes for InterfaceType and it seems not to be supported in ClassGenerator. Is it intentional?

selection is like

interfacetype {
    somefield
}

but I'm crashing on

throw new \Exception('Unsupported type '.get_class($namedType).' found.');

Unsupported type GraphQL\Type\Definition\InterfaceType found.

Thanks

Way to provide client implementation through DI

First of all, thank you for this project. Finally had a time to look at it and use it and it looks pretty solid!

I was looking for a way to provide a custom client implementation to query calls. Let's say I'd like to specify a curl implementation for my prod and dev env and mock implementation for my test env.

I have a service that is calling an endpoint generated by this library:

Query::execute()

How can I provide a mock client from certain test case? Thanks.

public function testService() {
     $c = new ClientMock('expected response');
     $s = new Service();
     // how to pass $c?
     self::assertSth($s->run());
}

Minify query strings

Is your feature request related to a problem? Please describe.

Query strings could be printed more compactly by omitting some whitespace. This would shave off a few bytes from each request and make both transmission and parsing quicker.

Describe the solution you'd like

{
  foo(bar: "baz")
}
{foo(bar:"baz")}

Describe alternatives you've considered

Leave them pretty printed.

Support operations with client directives

Hello,

I am trying to use directives :

query MyQuery($withNames: Boolean!, $withDescriptors: Boolean!) {
  molecule(limit: 5) {
    ...names @include(if: $withNames)
    ...descriptors @include(if: $withDescriptors) 
  }
}

but vendor/bin/sailor says:

"Variable \"$withNames\" is never used in operation \"MoleculeExport\"
"Variable \"$withDescriptors\" is never used in operation \"MoleculeExport\"

Add ability to fetch a remote schema through Introspection

Is your feature request related to a problem? Please describe.

Sailor requires access to the full schema of a targeted endpoint in order to generate typesafe code.

Describe the solution you'd like

Use the standard introspection query mechanism to fetch a remote schema and use that. As of now, graphql-php does not support construction of a schema from the result of an intrespection query.

The graphql-js implementation has such a utility:https://github.com/graphql/graphql-js/blob/master/src/utilities/buildClientSchema.js

See https://github.com/spawnia/sailor/tree/introspection

Describe alternatives you've considered

As an easy fix, we might support servers that follow the Apollo Federation spec, which conveniently adds a field _service.sdl that returns the schema as a string. We can work with that already.

https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#fetch-service-capabilities

Support PSR-18 clients

Is your feature request related to a problem? Please describe.

Dropping guzzle as a dependency in v0.8.0 is a nice step forward but two steps need to be done actually.

I have tons of PSR-18 client implementations available but in this lib I'm required to implement Spawnia\Sailor\Client instead which kind of reinvents the wheel.

Describe the solution you'd like

Accept PSR-compatible clients instead.

Doing this now which is a bit cumbersome

        return new class ($client) implements Client {
                public function __construct(private ClientInterface $client)
                {
                }

                public function request(string $query, \stdClass $variables = null) : Response
                {
                    $psr17Factory = new Psr17Factory();
                    $requestFactory = new GraphQLRequestFactory($psr17Factory, $psr17Factory);

                    /** @var array<string, mixed> $variablesArray */
                    $variablesArray = (array) $variables;

                    $request = $requestFactory->createRequest('', $query, $variablesArray);
                    $response = $this->client->sendRequest($request);

                    return Response::fromResponseInterface($response);
                }
            };

Allow other HTTP Client Implementations

This Library is very intresting!
Thank you for the effort so far.

Is your feature request related to a problem? Please describe.

We are currently already using Symfony HttpClient and with this library we would add Guzzle as another dependency.
It would be great if one could provide the client of their choice to sailor.

Describe the solution you'd like

As far as i know, sailor should require a PSR-18? Interface instead of the Guzzle Client directly.

Enhance functionality of value objects

Is your feature request related to a problem? Please describe.

The funtionality of TypedObject and plain input types added in #39 is pretty limited in some respects:

  • validation
  • serialization
  • other stuff we don't know about yet?

See #39 (comment)

Describe the solution you'd like

The generated classes should provide more advanced functionality. https://github.com/spatie/data-transfer-object might be just what we need.

Describe alternatives you've considered

We could also write such functionality ourselves or use another base library.

Add filename when validator return exception

Hello,

Validator return this kind of message :

{"message":"Field "molecule" is not defined by type molecule_bool_exp.","extensions":{"category":"g
raphql"},"locations":[{"line":2,"column":67}]}

But does not give info about the filename.

Many thanks for your work.

Eric

Compatibility with PHP 8.3 and Symfony 7.0

Is your feature request related to a problem? Please describe.

I'm trying to use this library in my symfony 7.0 project which runs on PHP 8.3, but having a problem installing it:

Using version ^0.30.1 for spawnia/sailor
./composer.json has been updated
Running composer update spawnia/sailor
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires spawnia/sailor ^0.30.1 -> satisfiable by spawnia/sailor[v0.30.1].
    - spawnia/sailor v0.30.1 requires symfony/var-exporter ^5.3 || ^6 -> found symfony/var-exporter[v5.3.0, ..., v5.4.32, v6.0.0, ..., v6.4.2] but the package is fixed to v7.0.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require spawnia/sailor:*" to figure out if any version is installable, or "composer require spawnia/sailor:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Describe the solution you'd like

I would like composer require spawnia/sailor to be completed without errors with Symfony 7.0 and PHP 8.3

Describe alternatives you've considered

There are no alternatives currently exists.

Handle Exception that isClientSafe()

Is your feature request related to a problem? Please describe.

If the server throws a client safe exception ( isClientSafe() === true) there should be a way to handle/recognize this appropriately.

Describe the solution you'd like

The exception that was client-safe on the origin-server should be forwarded as isClientSafe() === true to the client through the intermediate-server/caller

Describe alternatives you've considered

  • A config file that indicates how client safe exceptions should be handled
  • a per-request configuration that indicates how client safe exceptions should be handled on this request

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.