Skip to content

Commit

Permalink
fix(nexus): Support Nexus 1.0.0 (#182)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Upgrading nexus minimum version to 1.0.0
  • Loading branch information
lewebsimple authored and Sytten committed Dec 24, 2020
1 parent 6b2730b commit 22ea271
Show file tree
Hide file tree
Showing 20 changed files with 848 additions and 949 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Overview

Nexus Shield is a [@nexus/schema](https://github.com/graphql-nexus/schema) plugin that helps you create an authorization layer for your application. It is a replacement for the provided authorization plugin. It is heavily inspired by [Graphql Shield](https://github.com/maticzav/graphql-shield) and reuses most of it's familiar ruling system. It takes full advantage of the type safety provided by nexus.
Nexus Shield is a [nexus](https://github.com/graphql-nexus/nexus) plugin that helps you create an authorization layer for your application. It is a replacement for the provided authorization plugin. It is heavily inspired by [Graphql Shield](https://github.com/maticzav/graphql-shield) and reuses most of it's familiar ruling system. It takes full advantage of the type safety provided by nexus.

## Install

Expand Down
2 changes: 1 addition & 1 deletion examples/complex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "ts-node-dev --no-notify --transpileOnly --respawn src/server.ts"
},
"dependencies": {
"@nexus/schema": "^0.16.0",
"nexus": "^1.0.0",
"apollo-server": "^2.18.2",
"graphql": "^15.3.0",
"nexus-shield": "^1.1.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/complex/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType, stringArg } from '@nexus/schema';
import { extendType, objectType, stringArg } from 'nexus';

import { chain, partial, ruleType } from 'nexus-shield';
import { isAuthenticated, isAdmin } from './rules';
Expand Down
2 changes: 1 addition & 1 deletion examples/complex/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { allow, nexusShield } from 'nexus-shield';
import { ApolloServer, ForbiddenError } from 'apollo-server';
import * as path from 'path';
import { makeSchema } from '@nexus/schema';
import { makeSchema } from 'nexus';

import * as types from './schema';
import { createContext } from './context';
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "ts-node-dev --no-notify --transpileOnly --respawn src/server.ts"
},
"dependencies": {
"@nexus/schema": "^0.14.0",
"nexus": "^1.0.0",
"apollo-server": "^2.14.4",
"graphql": "^14.5.0",
"nexus-shield": "^1.0.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType, stringArg } from '@nexus/schema';
import { extendType, objectType, stringArg } from 'nexus';
import { ruleType } from 'nexus-shield';

export const Test = objectType({
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { allow, nexusShield } from 'nexus-shield';
import { ApolloServer, ForbiddenError } from 'apollo-server';
import * as path from 'path';
import { makeSchema } from '@nexus/schema';
import { makeSchema } from 'nexus';

import * as types from './schema';

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"object-hash": "^2.0.3"
},
"devDependencies": {
"@nexus/schema": "0.20.1",
"nexus": "1.0.0",
"@types/jest": "26.0.19",
"@types/node": "14.14.14",
"@types/object-hash": "1.3.4",
Expand Down Expand Up @@ -49,7 +49,7 @@
"typescript": "4.1.3"
},
"peerDependencies": {
"@nexus/schema": "^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0 || ^0.18.0 || ^0.19.0 || ^0.20.0",
"nexus": "^1.0.0",
"graphql": "^14.5.0 || ^15.0.0"
},
"files": [
Expand Down
7 changes: 2 additions & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { plugin } from '@nexus/schema';
import {
printedGenTyping,
printedGenTypingImport,
} from '@nexus/schema/dist/utils';
import { plugin } from 'nexus';
import { printedGenTyping, printedGenTypingImport } from 'nexus/dist/utils';
import * as hash from 'object-hash';

import { allow } from './builders';
Expand Down
6 changes: 3 additions & 3 deletions src/rules/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../config';
import {
Expand Down Expand Up @@ -28,7 +28,7 @@ export class BaseRule<TypeName extends string, FieldName extends string>
}

async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down Expand Up @@ -56,7 +56,7 @@ export class BaseRule<TypeName extends string, FieldName extends string>
private cacheable(
key: string
): (
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo
Expand Down
6 changes: 3 additions & 3 deletions src/rules/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../config';

Expand Down Expand Up @@ -27,7 +27,7 @@ export interface ShieldRuleOptions {

export interface ShieldRule<TypeName extends string, FieldName extends string> {
resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand All @@ -40,7 +40,7 @@ export type ShieldRuleFunction<
TypeName extends string,
FieldName extends string
> = (
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'>,
info: GraphQLResolveInfo
Expand Down
6 changes: 3 additions & 3 deletions src/rules/logic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from './interface';
Expand All @@ -16,7 +16,7 @@ export class LogicRule<TypeName extends string, FieldName extends string>
* By default logic rule resolves to false.
*/
async resolve(
_root: RootValue<TypeName>,
_root: SourceValue<TypeName>,
_args: ArgsValue<TypeName, FieldName>,
_ctx: GetGen<'context'> & ShieldContext,
_info: GraphQLResolveInfo,
Expand All @@ -29,7 +29,7 @@ export class LogicRule<TypeName extends string, FieldName extends string>
* Evaluates all the rules.
*/
async evaluate(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down
4 changes: 2 additions & 2 deletions src/rules/operators/and.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
Expand All @@ -17,7 +17,7 @@ export class RuleAnd<
* Makes sure that all of them have resolved to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down
6 changes: 3 additions & 3 deletions src/rules/operators/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
Expand All @@ -17,7 +17,7 @@ export class RuleChain<
* Makes sure that all of them have resolved to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand All @@ -40,7 +40,7 @@ export class RuleChain<
* Evaluates all the rules.
*/
async evaluate(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down
4 changes: 2 additions & 2 deletions src/rules/operators/not.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
Expand All @@ -24,7 +24,7 @@ export class RuleNot<
*
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down
4 changes: 2 additions & 2 deletions src/rules/operators/or.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
Expand All @@ -17,7 +17,7 @@ export class RuleOr<
* Makes sure that at least one of them has evaluated to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down
6 changes: 3 additions & 3 deletions src/rules/operators/race.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
Expand All @@ -17,7 +17,7 @@ export class RuleRace<
* Makes sure that at least one of them resolved to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand All @@ -42,7 +42,7 @@ export class RuleRace<
* Evaluates all the rules.
*/
async evaluate(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType } from '@nexus/schema';
import { extendType, objectType } from 'nexus';
import { AuthenticationError } from 'apollo-server';

import { ruleType } from '../../src';
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeSchema } from '@nexus/schema';
import { makeSchema } from 'nexus';
import { ApolloServer, ForbiddenError } from 'apollo-server';
import * as path from 'path';

Expand Down
Loading

0 comments on commit 22ea271

Please sign in to comment.