Skip to content

Instantly share code, notes, and snippets.

@tattali
Last active January 2, 2022 16:43
Show Gist options
  • Save tattali/ce7462d702806f4cca7221492039b84e to your computer and use it in GitHub Desktop.
Save tattali/ce7462d702806f4cca7221492039b84e to your computer and use it in GitHub Desktop.
Api Platform + GraphQL + Apollo + TypeScript

Api Platform + GraphQL + Apollo + TypeScript

Symfony | Api Platform | GraphQL | Apollo | TypeScript | React Hooks

Backend

Install Api Platform

composer req api

Install GraphQL

composer req webonyx/graphql-php

Frontend

Install apollo and graphql

yarn add apollo-boost @apollo/react-hooks graphql

Install codegen for typescript this will generate the types and interfaces automatically

yarn add @graphql-codegen/cli @graphql-codegen/typescript

Configure codegen

# codegen.yml
schema: http://localhost:8000/api/graphql
generates:
  src/services/graphql/types.ts:
    - typescript

run codegen to generate the types in src/services/graphql/types.ts

yarn graphql-codegen
@onurkose
Copy link

onurkose commented Jan 2, 2022

In case you are using SSL on your localhost:8000, run the command like this:

NODE_TLS_REJECT_UNAUTHORIZED=0 yarn graphql-codegen

Also, if you implemented JWT auth to access your graphql endpoints, use this codegen configuration:

schema:
  - 'https://your-graphql-url':
      headers:
        authorization: 'Bearer ...'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment