Swydo / meteor-graphql

Compiler plugin that supports GraphQL files in Meteor
MIT License
58 stars 5 forks source link

Still work, when don't use import? #44

Open thearabbit opened 5 years ago

thearabbit commented 5 years ago

I have 2 schema Assignee and Task

type Assignee {
  _id: String!
  name: String!
  gender: String!
}
#import "../assignees/schema.graphql"

type Task {
  _id: String!
  title: String!
  description: String
  assignee: Assignee
}

It work fine. But still work, if I remove #import ....? Could explain me? (I use merge-graphql-schemas to merge)

jamiter commented 5 years ago

Hi. Maybe it was cached somewhere. I can't say without knowing you're complete setup.

thearabbit commented 5 years ago

thanks for your reply.

// Client
import { Meteor } from 'meteor/meteor'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloLink } from 'apollo-link'
import { HttpLink } from 'apollo-link-http'
import { MeteorAccountsLink } from 'meteor/apollo'

export default new ApolloClient({
  link: ApolloLink.from([
    new MeteorAccountsLink(),
    new HttpLink({
      uri: Meteor.absoluteUrl('graphql'),
    }),
  ]),
  cache: new InMemoryCache(),
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'no-cache',
      errorPolicy: 'ignore',
    },
    query: {
      fetchPolicy: 'no-cache',
      errorPolicy: 'all',
    },
  },
})
---------------
// Server
import { ApolloServer, AuthenticationError } from 'apollo-server-express'
import { WebApp } from 'meteor/webapp'
import { getUser } from 'meteor/apollo'
import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'

// Get schemas
import { typeDefs, resolvers } from './apollo-schema'

// Create apollo server
const server = new ApolloServer({
  typeDefs: mergeTypes(typeDefs, { all: true }),
  resolvers: mergeResolvers(resolvers),
  context: async ({ req }) => {
    const user = await getUser(req.headers.authorization)
    // In the browser console, enter
    // localStorage.getItem('Meteor.loginToken')
    if (user) return { user }

    console.log('AuthenticationError: You must be logged in')
    throw new AuthenticationError('You must be logged in')
  },
})

server.applyMiddleware({
  app: WebApp.connectHandlers,
  path: '/graphql',
})

WebApp.connectHandlers.use('/graphql', (req, res) => {
  if (req.method === 'GET') {
    res.end()
  }
})