Skip to content

Commit

Permalink
Remove the 'query: Query' field from Query
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Mar 27, 2020
1 parent 51dba15 commit f9fd1a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions @app/server/src/middleware/installPostGraphile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getHttpServer, getWebsocketMiddlewares } from "../app";
import OrdersPlugin from "../plugins/Orders";
import PassportLoginPlugin from "../plugins/PassportLoginPlugin";
import PrimaryKeyMutationsOnlyPlugin from "../plugins/PrimaryKeyMutationsOnlyPlugin";
import RemoveQueryQueryPlugin from "../plugins/RemoveQueryQueryPlugin";
import SubscriptionsPlugin from "../plugins/SubscriptionsPlugin";
import handleErrors from "../utils/handleErrors";
import { getAuthPgPool, getRootPgPool } from "./installDatabasePools";
Expand Down Expand Up @@ -153,6 +154,10 @@ export function getPostGraphileOptions({
* https://www.graphile.org/postgraphile/extending/
*/
appendPlugins: [
// PostGraphile adds a `query: Query` field to `Query` for Relay 1
// compatibility. We don't need that.
RemoveQueryQueryPlugin,

// Adds support for our `postgraphile.tags.json5` file
TagsFilePlugin,

Expand Down
15 changes: 15 additions & 0 deletions @app/server/src/plugins/RemoveQueryQueryPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Plugin } from "postgraphile";

const RemoveQueryQueryPlugin: Plugin = (builder) => {
builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
if (context.scope.isRootQuery) {
const { query, ...rest } = fields;
// Drop the `query` field
return rest;
} else {
return fields;
}
});
};

export default RemoveQueryQueryPlugin;
6 changes: 0 additions & 6 deletions data/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,6 @@ type Query {
"""The method to use when ordering `Organization`."""
orderBy: [OrganizationsOrderBy!] = [PRIMARY_KEY_ASC]
): OrganizationsConnection

"""
Exposes the root query type nested one level down. This is helpful for Relay 1
which can only query top level fields if they are in a particular form.
"""
query: Query!
user(id: UUID!): User
userAuthentication(id: UUID!): UserAuthentication
userByUsername(username: String!): User
Expand Down

0 comments on commit f9fd1a2

Please sign in to comment.