this._worker is null when I call GraphQLAPI.setSchema, so it throws (TypeError): this.worker is not a function

Example repo: https://github.com/cshaver/nextjs-monaco-graphql-example/commit/61df7029ac9f724c18b7b7c9d4a10d5c1e71233d
Deployed to: https://nextjs-monaco-graphql-example-git-ex-setschema.crit.vercel.app/
seems like you're having an issue with mounting your worker! let me look at it some more
this would be an issue with something other than setSchema(). it means that your build does not seem to have the graphql worker present and registered. are other language service features working?
@acao I see now! This happens when calling setSchema() prior to the the worker loading (e.g. in the same place as setSchemaConfig from the example: https://github.com/graphql/graphiql/blob/main/examples/monaco-graphql-webpack/src/index.ts#L107). Calling setSchema() after a timeout works just fine.
@cshaver I come across the prolem as well. Then i try to calling setSchema() in setTimeout. this._worker is not null now, but when I try to use the type declared in the schema, monaco shows unknow type error. Did you meet the problem too?

@cshaver what do you propose we add to monaco-graphql to ameliorate this issue? i'm about to go on a lengthy vacation!
@acao To fix the need for a timeout I think we can wrap the worker getter in a promise, since the functions that call the worker are async already. ~I got something working locally here.~ See PR #1648
@fanbitian I ran into that as well! I think subsequent calls to getSchema cause the schema to be loaded again from the defaultSchemaLoader + configured URI, overwriting the manually set schema. 馃
@acao What if we did something like make SchemaConfig optional, and skip fetching the schema when it's not present? (e.g. for my current use case the graphql schema is what's being edited, so we would only ever be setting the schema directly, never loading it from a server)
@cshaver Since setSchema is not work well, I calls updateSchemaConfig to send the schema to the server and it response with a merged one. And now I can use the type declared in the schema. This is not a good solution, because it requires network resource. As you mentioned, I also wish the schema could be set directly instead loading from a server.
fixed in monaco-graphql 0.3.1-alpha.2
setSchema() now accepts either an SDL string or GraphQLSchema primitive. enjoy!
Most helpful comment
@cshaver I come across the prolem as well. Then i try to calling

setSchema()insetTimeout.this._workeris notnullnow, but when I try to use the type declared in the schema, monaco shows unknow type error. Did you meet the problem too?