Skip to content

Commit

Permalink
docs: add example section
Browse files Browse the repository at this point in the history
  • Loading branch information
vuongxuongminh committed Mar 27, 2024
1 parent ba84278 commit 80ceb99
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,53 @@ then generate PHP code with command:
./vendor/bin/x-graphql-codegen x-graphql:codegen:generate
```

Example
-------

Add `x-graphql/http-schema` package for executing schema over http:

```shell
composer require x-graphql/http-schema
```

Init config file:

```shell
./vendor/bin/x-graphql-codegen x-graphql:codegen:init-config
```

Add `example.graphql` to your current working directory with content:

```graphql
query getCountries {
countries {
name
}
}
```

Run command to generate PHP code:

```shell
./vendor/bin/x-graphql-codegen x-graphql:codegen:generate
```

Use generated query class:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

$delegator = new \XGraphQL\HttpSchema\HttpDelegator('https://countries.trevorblades.com/');
$schema = \XGraphQL\HttpSchema\HttpSchemaFactory::createFromIntrospectionQuery($delegator);
$query = new \App\GraphQL\Codegen\GraphQLQuery($schema);

$result = $query->getCountries();

var_dump($result->toArray());
```

Credits
-------

Expand Down

0 comments on commit 80ceb99

Please sign in to comment.