how to use .graphql in a typescript node project without webpack

后端 未结 3 674
慢半拍i
慢半拍i 2020-12-20 16:56

I have a node, express server using expressGraphql. I am trying to declare a type definition for graphql in a .graphql or .gql file, because as the

3条回答
  •  暖寄归人
    2020-12-20 17:31

    AFAIK, there are two ways to import schema files, either 1) by reading the file directly as you describe above, or 2) by wrapping the queries in exported variables.

    // bookSchema.ts <- note the file extension is .ts instead of .graphql
    export default `
      type Book {
        message: String
      }
    `
    
    // anotherSchema.ts <- note the file extension is .ts instead of .graphql
    export default `
      type User {
        name: String
      }
    `
    
    // main.ts
    import bookSchema from 'bookSchema';
    import anotherSchema from 'anotherSchema';
    
    const schema = makeExecutableSchema({ typeDefs: [
      bookSchema,
      anotherSchema,
    ] });
    

提交回复
热议问题