0

I have a problem with GraphQL and I want to create a federation with Laravel 9. I use: https://lighthouse-php.com/5/federation/getting-started.html to create monolog GraphQL and created 2 Laravel projects named "a" and "b". they work separately good. "a" project has a person table with schema(id, name), and the second project has a post table with schema(id, text,person_id) I want to get person_id from "a" project with GraphQL federation. As I search for federation in other languages I found this link: https://www.apollographql.com/docs/federation/federation-spec/#type-_service and I defined it to my schema but it shows me that there aren't any @key-@extends-@external,... directive for that. I create a directive with the Laravel command: "PHP artisan lighthouse: directive --argument Key" and I created also it for "extend" and "external" but I don't know how can I write down my code in @key resolver and @extends and @external directives. Can anyone help me?

user2889491
  • 3
  • 1
  • 1
  • 3

1 Answers1

0

The necessary directives are available in Lighthouse after enabling federation, no need for you to define them. To aid autocompletion and satisfy IDE plugins, use php artisan lighthouse:ide-helper - see https://lighthouse-php.com/5/api-reference/commands.html#ide-helper

spawnia
  • 879
  • 6
  • 13
  • after PHP artisan lighthouse:ide-helper it created 3 files(schema-directives.graphql-programmatic-types.graphql-_lighthouse_ide_helper.php) successfully but before I use the defined directive('@key'-'@extends'-'@external') it gives me "Could not locate a field resolver for the query: _entities.\n\nEither add a resolver directive such as '@all', '@find' or '@create' or add\na resolver class through:\n\nphp artisan lighthouse: query _entities\n" error, I used '@all' instead of resolver for that. – user2889491 Jun 01 '22 at 07:19
  • and also for _serice(_service: _Service! @all) and run again it shows me "Failed to find class extends GraphQL\\Type\\Definition\\ScalarType in namespaces [App\\GraphQL\\Scalars] for the scalar _Any." error for scaler _Any and scalar _FieldSet so I created them by "PHP artisan lighthouse: scalar _Any and _FieldSet for that and my type is like(type Post @key(fields: "person_id") @extends{ id: ID text: String person_id: Int @external }) the playground runs without any error and does all of the changes for the project an also and runs. am I right? – user2889491 Jun 01 '22 at 07:20
  • I created gateway and changed the "b" project like :type Post @key(fields: "id") { id:Int text:String person_id:Int person:Person } – user2889491 Jun 01 '22 at 09:41
  • type Person @key(fields: "id") @extends{ id: Int @external } – user2889491 Jun 01 '22 at 09:41
  • the result is : { "data": { "getPost": { "id": 1, "text": "text for 1", "person_id": 1, "person": null } } } – user2889491 Jun 01 '22 at 09:42