GraphQL Integration

Access all generated GDL entities through a single unified endpoint with high-efficiency queries.

Single Unified Endpoint

Rather than relying entirely on REST endpoints, your application supports GraphQL via POST /graphql.

Note: Just like REST, GraphQL requires standard Keycloak JWT headers to be attached to queries and mutations!

# Example: Querying Multiple Data Models (GORM Relational Mapping Handles JOINs)
query {
  getEntity(id: 1) {
    id
        name
  }
}

Working with Frontend Libraries

Here is how to seamlessly execute your generated queries inside modern JavaScript frameworks using fetch.

const fetchEntity = async () => {
  const query = \`
    query {
      listEntitys(page: 1, size: 5) {
        id
        name
      }
    }
  \`;

  const response = await fetch('http://localhost:8080/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_JWT'
    },
    body: JSON.stringify({ query })
  });
  
  const { data } = await response.json();
  console.log('Result array:', data);
};