How do I import this graphql schema from a .graphql file?

type Thread {
    _id: ID!
}


input ThreadParams {
    _id: ID
    type: String
}

type Query {
    threads(params: ThreadParams): [Thread],
  }


type Mutation {
	createThread(params: ThreadParams): Thread
}


Typically I just throw it in one big string like

export const ThreadSchema = [`
type Thread {
    _id: ID!
}


input ThreadParams {
    _id: ID
    type: String
}

type Query {
    threads(params: ThreadParams): [Thread],
  }


type Mutation {
	createThread(params: ThreadParams): Thread
}


`]


export const typeDefs = [
  ...ThreadSchema
];

export const resolvers = merge( ThreadResolvers ); //ThreadResolvers not shown here

then in another file:


// Load all your resolvers and type definitions into graphql-loader
loadSchema({ typeDefs, resolvers });

// Gets all the resolvers and type definitions loaded in graphql-loader
export const schema = makeExecutableSchema(getSchema());

how does this work with graphql files (in meteor)?

See how it’s done here

I have it working that way (holding the graphql stuff inside a es6 strings in an array). My question is how would I do that same exact thing, using a .graphql file.

I tried this but it doesn’t seem to be working for me: New: import .graphql files in Meteor!

If you’re looking at writing queries/types in .graphql or .gql files and use imports to load fragments, see this Medium post “Webpack’ing your GraphQL Documents”

1 Like

I think I answered this here:

No need for webpack. swydo:graphql should do the trick. It uses the exact same loader as webpack underwater.

2 Likes