4
votes

I have implemented api_platform in my symfony 4 project, the problem is that I have to use the paths provided by the Rest api to fetch data using graphql like this

{
  user(id:"api/users/1")
  {
    id
  }
}

rather than

{
  user(id:1){
  id
  }
}

Went through the documentation and didn't find a solution for this. Using plain api paths in graph api isn't really worth moving to graphql. Any help.

2
Why do you need to use the path containing the id instead of the id only? Is there any particular reason for this? - fgamess
@franck_gamess I want to use the Id only, api platform provide graphql queries by path - Convict Moody

2 Answers

0
votes

libraries like Prisma Binding allows you to query GraphQL using APIs

example on fetch user with ID of 1:

const query = `
  query ($userId: ID!){
    user(id: $userId) {
      id
      name
    }
  }
`

const variables = { userId: '1' }

prisma.request(query, variables).then(result => console.log(result))
// {"data": { "user": { "id": "1", "name": "Sarah" } } }

From here, we can write custom wrappers to translate the REST endpoints to corresponding queries

0
votes

You can handle that in the resolver function, so you will receive a string param in the PHP resolver function instead of int(id). check this example: https://github.com/khaledalam/simple-system-with-graphql-react-php