Git Product home page Git Product logo

graphql-demo's Introduction

[ARCHIVED] GraphQL for Microsoft Graph (DEMO)

Note: This repo is archived and no longer actively maintained. Security vulnerabilities may exist in the project, or its dependencies. If you plan to reuse or run any code from this repo, be sure to perform appropriate security checks on the code or dependencies first.

Call to action

We are looking for feedback from developers interested in integrating with Microsoft Graph via GraphQL. To share your thoughts and scenarios, please leave a comment on UserVoice.

About

This is a demo that enables basic, read-only querying of the Microsoft Graph API using GraphQL query syntax. GraphQL enables clients to request exactly the resources and properties that they need instead of making REST requests for each resource and consolidating the responses. To create a GraphQL service, this demo translates the Microsoft Graph OData $metadata document to a GraphQL schema and generates the necessary resolvers. Please note we are providing this demo code for evaluation as-is.

Animation of sample request

Live demo

Try the Microsoft Graph GraphQL Demo here

Installation

  1. Clone the repo
  2. Install dependencies (npm install)
  3. Generate schema description and resolver code using npm run build
  4. Navigate to the App Registration Portal, set up a new web app
  5. Configure App Id and redirect URIs in the AppConfiguration of build/index.html
  6. Run npm start and go to localhost:1337

Sample requests

Fetch recent emails

{
  me {
    displayName
    officeLocation
    skills
    messages {
      subject
      isRead
      from {
        emailAddress {
          address
        }
      }
    }
  }
}

Fetch groups and members

{
  groups {
    displayName
    description
    members {
      id
    }
  }
}

Fetch files from OneDrive

{
  me {
    drives {
      quota {
        used
        remaining
      }
      root {
        children {
          name
          size
          lastModifiedDateTime
          webUrl
        }
      }
    }
  }
}

How it works

  • src/setup.js reads in a well-formed $metadata CSDL, parses it and builds up a GraphQL schema
  • src/setup.js code generates resolvers that naively issues requests to the Graph service when the previous (parent) resolver doesn't have the data at hand

Limitations/to-dos

  • Translate OData inheritance relationships
  • Enable passing arguments (id for indexing into collections)
  • Support pagination
  • Implement mutations
  • Enable passing arguments for sort, filter
  • Add heuristics for $expand to reduce number of service calls made

Code of conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Copyright

Copyright (c) 2017 Microsoft Corporation.

graphql-demo's People

Contributors

dan-silver avatar dpim avatar jthake avatar keyur32 avatar nokafor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-demo's Issues

Permissions Workflow for Groups Example

I realize this might be a permissions issue, but not sure if I need to consent the AADv2 auth tokens in a specific way to get the example to work with the groups endpoint.

Issue

Attempting to execute the example group query which hits

{
  groups {
    displayName
    description
    members {
      id
    }
  }
}

Result:

{
  "errors": [
    {
      "message": "Expected Iterable, but did not find one for field Query.groups.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "groups"
      ]
    }
  ],
  "data": {
    "groups": null
  }
}

From the console:

GraphQL API server running on port:1337
{ StatusCodeError: 403 - "{\r\n  \"error\": {\r\n    \"code\": \"Authorization_RequestDenied\",\r\n
  \"message\": \"Insufficient privileges to complete the operation.\",\r\n    \"innerError\": {\r\n
    \"request-id\": \"2506310d-deda-4284-8004-db376b2818d7\",\r\n      \"date\": \"2018-02-15T18:32:18\"\r\n    }\r\n  }\r\n}"
    at new StatusCodeError (C:\github\graphql-demo\node_modules\request-promise-core\lib\errors.js:32:15)
    at Request.plumbing.callback (C:\github\graphql-demo\node_modules\request-promise-core\lib\plumbing.js:104:33)
    at Request.RP$callback [as _callback] (C:\github\graphql-demo\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at Request.self.callback (C:\github\graphql-demo\node_modules\request\request.js:186:22)
    at emitTwo (events.js:125:13)
    at Request.emit (events.js:213:7)
    at Request.<anonymous> (C:\github\graphql-demo\node_modules\request\request.js:1163:10)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at IncomingMessage.<anonymous> (C:\github\graphql-demo\node_modules\request\request.js:1085:12)
    at Object.onceWrapper (events.js:314:30)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1059:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'StatusCodeError',
  statusCode: 403,
  message: '403 - "{\\r\\n  \\"error\\": {\\r\\n    \\"code\\": \\"Authorization_RequestDenied\\",\\r\\n    \\"message\\": \\"Insufficient privileges to complete the operation.\\",\\r\\n    \\"innerError\\": {\\r\\n      \\"request-id\\": \\"2506310d-deda-4284-8004-db376b2818d7\\",\\r\\n      \\"date\\": \\"2018-02-15T18:32:18\\"\\r\\n    }\\r\\n  }\\r\\n}"',
  error: '{\r\n  "error": {\r\n    "code": "Authorization_RequestDenied",\r\n    "message": "Insufficient privileges to complete the operation.",\r\n    "innerError": {\r\n      "request-id": "2506310d-deda-4284-8004-db376b2818d7",\r\n      "date": "2018-02-15T18:32:18"\r\n    }\r\n  }\r\n}',
  options:
   { url: 'https://graph.microsoft.com/v1.0/groups',

Steps Taken

  1. Generated an AD v2 ("convergent") API Key through dev portal
    • Web platform
    • Redirect URI: http://localhost:1337
    • Delegated Permissions: same as those listed in applicationConfig.scopes object in index.html
  2. Update index.html
  3. [...] npm start
  4. SSO with personal creds

Does anyone is maintaining this repository?

If someone is maintaining this repo and if they have any documents for how this project started and which document is prepared and way to extend this demo it would be very helpful to understand and learn from all efforts done for this repository.

If we get some documents then it would be very helpful.

Discussion: Use of intermediate graphql file

Before reviewing #3, I was wondering if we can discuss the use of an intermediate graphql file? If I understand the project correctly, it downloads a metadata file, parses it, writes a .graphql file, then reads that file and passes it to makeExecutableSchema.

When initially coding this project, did you consider directly creating the graphql objects? There's a great example in the graphql-js project of dynamically building a schema rather than reading a graphql file. I'm wondering if it's simpler to directly map to these types? So, after parsing the metadata file we have some structure in memory and instead of using that to write a schema to a file we create an in memory map of all the OData types. For example the mapping would be Edm.String to GraphQLString and entities would map to GraphQLObjectType.

I think we could get rid of a few dependencies like acorn, astring, graphql-tools, etc. I haven't thought this through all the way, but it might also be easier to use this pattern to add all the other HTTP verbs and OData query parameters. This also means we could get rid of the npm run build step and just have an npm run start. The metadata could be downloaded on the first request or on server start.

Are there other advantages to generating a graphql schema file? If we still want it, there might be a way to have graphql-js export it for us.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.