remix-graphql
remix-graphql copied to clipboard
use .graphql files
Hello
Can we use .graphql files for the schema?
Hello @seanaguinaga 👋 you definitely can! This isn't built into remix-graphql
per se, but it should be straight-forward to make this work using makeExecutableSchema
from the @graphql-tools/schema
package (see here).
It could look something like this:
# File ~/app/graphql/schema.graphql
type Query {
hello: String
}
// File ~/app/graphql/schema.server.ts
import { makeExecutableSchema } from "@graphql-tools/schema";
import fs from "fs";
import path from "path";
// Load the type definitions from the file system
const typeDefs = fs.readSync(path.join(__dirname, "schema.graphql"));
// Define resolvers
const resolvers = {
Query: {
hello() {
return "world";
},
},
};
// Combine both into a schema and export that for usage with `remix-graphql`
export const schema = makeExecutableSchema({
typeDefs,
resolvers
});
@seanaguinaga did that work out for you? 👆 🙂
I think this is a common pattern (especially when using apollo
), would you be up to adding a section in the README about that?
@thomasheyenbrock gonna try it today!
Yeah I would!
Let me give it a go