Skip to content
45 changes: 12 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"follow-redirects": "1.7.0",
"graphql": "14.4.2",
"graphql-list-fields": "2.0.2",
"graphql-tools": "^4.0.5",
"graphql-upload": "8.0.7",
"intersect": "1.0.1",
"jsonwebtoken": "8.5.1",
Expand Down Expand Up @@ -76,6 +77,7 @@
"flow-bin": "0.102.0",
"form-data": "2.5.0",
"gaze": "1.1.3",
"graphql-tag": "^2.10.1",
"husky": "3.0.0",
"jasmine": "3.4.0",
"jsdoc": "3.6.3",
Expand Down
119 changes: 117 additions & 2 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ describe('ParseGraphQLServer', () => {
});
});

describe('API', () => {
describe('Auto API', () => {
let httpServer;

const headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-Javascript-Key': 'test',
Expand Down Expand Up @@ -340,7 +342,7 @@ describe('ParseGraphQLServer', () => {

beforeAll(async () => {
const expressApp = express();
const httpServer = http.createServer(expressApp);
httpServer = http.createServer(expressApp);
expressApp.use('/parse', parseServer.app);
ParseServer.createLiveQueryServer(httpServer, {
port: 1338,
Expand Down Expand Up @@ -384,6 +386,10 @@ describe('ParseGraphQLServer', () => {
});
});

afterAll(async () => {
await httpServer.close();
});

describe('GraphQL', () => {
it('should be healthy', async () => {
const health = (await apolloClient.query({
Expand Down Expand Up @@ -5100,4 +5106,113 @@ describe('ParseGraphQLServer', () => {
});
});
});

describe('Custom API', () => {
let httpServer;
const headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-Javascript-Key': 'test',
};
let apolloClient;

beforeAll(async () => {
const expressApp = express();
httpServer = http.createServer(expressApp);
parseGraphQLServer = new ParseGraphQLServer(parseServer, {
graphQLPath: '/graphql',
graphQLCustomTypeDefs: gql`
extend type Query {
custom: Custom @namespace
}

type Custom {
hello: String @resolve
hello2: String @resolve(to: "hello")
userEcho(user: _UserFields!): _UserClass! @resolve
}
`,
});
parseGraphQLServer.applyGraphQL(expressApp);
await new Promise(resolve => httpServer.listen({ port: 13377 }, resolve));
const httpLink = createUploadLink({
uri: 'http://localhost:13377/graphql',
fetch,
headers,
});
apolloClient = new ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
},
},
});
});

afterAll(async () => {
await httpServer.close();
});

it('can resolve a custom query using default function name', async () => {
Parse.Cloud.define('hello', async () => {
return 'Hello world!';
});

const result = await apolloClient.query({
query: gql`
query Hello {
custom {
hello
}
}
`,
});

expect(result.data.custom.hello).toEqual('Hello world!');
});

it('can resolve a custom query using function name set by "to" argument', async () => {
Parse.Cloud.define('hello', async () => {
return 'Hello world!';
});

const result = await apolloClient.query({
query: gql`
query Hello {
custom {
hello2
}
}
`,
});

expect(result.data.custom.hello2).toEqual('Hello world!');
});

it('should resolve auto types', async () => {
Parse.Cloud.define('userEcho', async req => {
return req.params.user;
});

const result = await apolloClient.query({
query: gql`
query UserEcho($user: _UserFields!) {
custom {
userEcho(user: $user) {
username
}
}
}
`,
variables: {
user: {
username: 'somefolk',
},
},
});

expect(result.data.custom.userEcho.username).toEqual('somefolk');
});
});
});
Loading