Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Api Platform + GraphQL + Apollo + TypeScript

Api Platform + GraphQL + Apollo + TypeScript

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


Install Api Platform

composer req api

Install GraphQL

composer req webonyx/graphql-php


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
    - typescript

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

yarn graphql-codegen
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:

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

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