Skip to content

Instantly share code, notes, and snippets.

@oplanre
oplanre / TSGen.php
Last active May 28, 2024 12:22
Simple TS interface generator (php impl)
<?php
class TSGen
{
public static function fromJSON(string $json, string $interfaceName): string
{
try {
return self::generateInterface(json_decode($json, true, 512, JSON_THROW_ON_ERROR), $interfaceName);
} catch (JsonException $e) {
throw new InvalidArgumentException("Error parsing JSON: " . $e->getMessage());
@ashbuilds
ashbuilds / server.ts
Last active December 31, 2024 13:34
Implementing GraphQL Subscriptions with Websockets in a Bun Server using graphql-yoga
import Bun from 'bun'
import { createYoga, YogaInitialContext, YogaServerInstance } from 'graphql-yoga'
import { makeHandler } from "graphql-ws/lib/use/bun";
import { ExecutionArgs } from "@envelop/types";
import { schema } from './graphql/schema';
interface IUserContext {
token?: string;
}