@teambit/bundler
Version:
88 lines (84 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.devServerSchema = devServerSchema;
function _client() {
const data = require("@apollo/client");
_client = function () {
return data;
};
return data;
}
function _events() {
const data = require("./events");
_events = function () {
return data;
};
return data;
}
function devServerSchema(bundler, graphql) {
return {
typeDefs: (0, _client().gql)`
extend type Component {
server: ComponentServer
}
type ComponentServer {
id: ID!
env: String
url: String
host: String
basePath: String
}
type Subscription {
componentServerStarted(id: String): [ComponentServer!]!
}
`,
resolvers: {
Component: {
server: (component, args, context) => {
// This is a bit of a hack to get the requested id. it assumes the variable name of
// the gotHost.get query is "id".
// see it in scopes/component/component/component.graphql.ts
const requestedId = context?.body?.variables?.id;
// if we ask for specific id with specific version it means we want to fetch if from scope
// so don't return the server url
// see https://github.com/teambit/bit/issues/5328
if (requestedId && requestedId.includes('@')) {
return {
id: 'no-server'
};
}
const componentServer = bundler.getComponentServer(component);
if (!componentServer) return {
id: 'no-server'
};
return {
id: `server-${componentServer.context.envRuntime.id}`,
env: componentServer.context.envRuntime.id,
url: componentServer.url
};
}
},
Subscription: {
componentServerStarted: {
subscribe: () => graphql.pubsub.asyncIterator([_events().ComponentServerStartedEvent]),
resolve: (payload, {
id
}) => {
const server = payload.componentServers;
if (!server || id && server.context.envRuntime.id !== id) {
return [];
}
return [{
id: `server-${server.context.envRuntime.id}`,
env: server.context.envRuntime.id,
url: server.url
}];
}
}
}
}
};
}
//# sourceMappingURL=dev-server.graphql.js.map